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

Reply via email to