How do I add headers to a CSV using ObjectScript?
I'm wondering how I would go about adding headers to a csv file which has already been created. I am unfamiliar with ObjectScript.
For example if I were to use R, I would simply write..
test <- read.csv("file/path/example/Extract.csv", header=FALSE)
colnames(test) <- c("A","B","C","D","E")
I do not have embedded Python installed either as I would know how to do it in that also.
How could I mirror this in ObjectScript please?
My current create file method:
Hi Leon,
You probably would need an init method that gets called if the file does not exist,
That creates the file and writes the csv header line.
Have a look at Using %Library.File | InterSystems IRIS Data Platform 2022.3, that should give some pointers on hoe to check, create file and writeLn to it.
Some ideas for an Operation.
Expose the Comma delimited headings to be configurable via new property and settings.
Toggle the overwrite/append mode, if set to overwrite, to ensure the heading is added to new files
So code code might be something like:
For updating existing files using streams:
May need to consider stream line terminators and character encoding.
I'd seriously consider using the Record Mapper. No code required.
See related Docs and Online Learning.