I'd like to thank everyone for replying.
I suppose I should think about using J7.
I did try Devon's example:
"You can read CSV files in J pretty simply without using any predefined
verbs like this:
mat=. <.;_1&>',',&.><;._2 CR-.~freads jpath '~temp/test.csv'
and I got the error:
|domain error
| mat=.<.; _1&>',',&.><;._2 CR-.~freads jpath'~temp/test.csv'
As an aside, I don't really understand what the "mat" function is doing. I'm
still reading
"J for C Programmers" so my understanding is a little shaky, but mat seems to
be monadic, with the argument as the file to read. I'm not sure if this is an
example of a tacit verb, because the argument ('~temp/test.csv') seems to be
hardcoded into the verb.
I assume:
freads jpath '~temp/test.csv'
reads the file.(http://www.jsoftware.com/user/script_files.htm)
I do not really understand this: ~freads (I do not understand this use of the
monadic tilde)
I am trying to read this verb from right to left, but am not getting very far,
even using the J dictionary and reference card for support.
I would really appreciate any help at all in deciphering this.
Thanks and regards,
Jon
> Date: Sat, 7 Dec 2013 08:16:47 +1300
> From: [email protected]
> To: [email protected]
> Subject: Re: [Jprogramming] Beginner Understanding CSV file reading/writing
>
> The strings script is combined as part of stdlib since J7. In J602, which
> Jon is using, the strings script was still separate (and had to be
> explicitly loaded to be available in a session). The SVN logs suggest the
> chopstring verb was added to strings in September 2008. I suspect that is a
> later version of the base library than is included in the J602 installer.
> On Dec 7, 2013 7:53 AM, "Devon McCormick" <[email protected]> wrote:
>
> > Also, I see "chopstring" defined in ~system/main/stdlib.ijs. I'm not sure
> > why the csv code doesn't find it.
> >
> >
> >
> > On Fri, Dec 6, 2013 at 1:39 PM, Devon McCormick <[email protected]>
> > wrote:
> >
> > > You can read CSV files in J pretty simply without using any predefined
> > > verbs like this:
> > >
> > > mat=. <.;_1&>',',&.><;._2 CR-.~freads jpath '~temp/test.csv'
> > >
> > > But this does not properly handle cases where the delimiter is embedded
> > in
> > > a string, e.g. a file like this will cause problems:
> > >
> > > 1,2,"embed, comma",4.5
> > > 6,7,"no embedded comma",8.9
> > >
> > > Also, I usually use the more general "dsv" (delimiter separated values)
> > > module as I prefer tab-delimited files. You can look at these here:
> > >
> > > load '~addons/tables/dsv/dsv.ijs'
> > > mat=. (',';'"') readdsv jpath '~temp/test.csv'
> > > NB. Read comma-delimited file with double-quotes around some items.
> > >
> > >
> > >
> > > On Fri, Dec 6, 2013 at 10:25 AM, Jon Hough <[email protected]> wrote:
> > >
> > >> I am a complete beginner to J. I am attempting to write and read CSV
> > >> files.
> > >>
> > >> My initial attempt is to follow this method:
> > >> http://www.jsoftware.com/jwiki/Addons/tables/csv
> > >>
> > >> I am using J-602 on 32-bit Linux.
> > >> My attempt has some differences to the output shown in the example.
> > >>
> > >> dat writecsv jpath '~temp/test.csv'
> > >> 45
> > >>
> > >> When I attempt this function it outputs 45, not 47 as in the example.
> > >> (Not that I really know what either indicate at the moment).
> > >>
> > >> Then when I try to read the csv table, which does exist in my temps
> > >> directory,
> > >> I get this output:
> > >>
> > >> ]datcsv=: freads jpath '~temp/test.csv'
> > >> 34,"45","hello",-5.34
> > >> 12,"32","goodbye",1.23
> > >>
> > >> fixcsv datcsv
> > >> |value error: chopstring
> > >> | >msk <@(x&chopstring);._2 y
> > >>
> > >> And then I do the following:
> > >>
> > >> chopstring
> > >> |value error: chopstring
> > >>
> > >> and:
> > >>
> > >> fixcsv
> > >> ┌────────────┐
> > >> │fixcsv_pcsv_│
> > >> └────────────┘
> > >>
> > >> and:
> > >>
> > >> writecsv
> > >> ┌──────────────┐
> > >> │writecsv_pcsv_│
> > >> └──────────────┘
> > >>
> > >> I am not sure what the final two outputs mean, but the
> > >>
> > >> |value error: chopstring
> > >>
> > >> appears to indicate that the function (verb?) chopstring does not exist.
> > >>
> > >> I am really interesting in using J to analyze datasets from CSV files,
> > >> and although I as a complete beginner, I would appreciate any help.
> > >>
> > >> Regards,
> > >> Jon
> > >>
> > >> ----------------------------------------------------------------------
> > >> For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > >
> > >
> > >
> > > --
> > > Devon McCormick, CFA
> > >
> > >
> >
> >
> > --
> > Devon McCormick, CFA
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm