Yes - sorry for typing it in w/o testing it. Note that the point at which
the error was picked up is indicated by extra spaces in the returned line:
mat=.<.; _1&>',',&.><;._2 CR-.~freads jpath'~temp/test.csv'
|domain error
| mat=.<.; _1&>',',&.><;._2 CR-.~freads jpath'~temp/test.csv'
A good way to to debug a line like this is to look at successively longer
pieces, starting w/the rightmost one, e.g. (on my system):
jpath '~temp/test.csv'
c:/users/devonmcc/j64-701-user/temp/test.csv
Do I have this file?
fexist jpath '~temp/test.csv'
0
So, I don't have this file - I only used it to mimic the example you sent.
If I create this file locally so I can continue looking at longer pieces:
('1,2,"embedded, comma",3.4',CR,LF,'5,6,"no comma",7.8') fwrite
'test.csv'
45
fexist 'test.csv'
1
BTW - "fexist" is defined
fexist=: 1:@(1!:4) ::0:@(([: < 8 u: >) ::]&>)@(<^:(L. = 0:))
in case you don't have it.
Continuing with longer fragments shows us what the data looks like at each
step:
NB. mat=. <.;_1&>',',&.><;._2 CR-.~freads 'test.csv'
freads 'test.csv'
1,2,"embedded, comma",3.4
5,6,"no comma",7.8
CR-.~freads 'test.csv'
1,2,"embedded, comma",3.4
5,6,"no comma",7.8
<;._2 CR-.~freads 'test.csv'
+-------------------------+------------------+
|1,2,"embedded, comma",3.4|5,6,"no comma",7.8|
+-------------------------+------------------+
',',&.><;._2 CR-.~freads 'test.csv'
+--------------------------+-------------------+
|,1,2,"embedded, comma",3.4|,5,6,"no comma",7.8|
+--------------------------+-------------------+
<.;_1&>',',&.><;._2 CR-.~freads 'test.csv'
|domain error
| <.; _1&>',',&.><;._2 CR-.~freads'test.csv'
Fixing the error:
<;._1&>',',&.><;._2 CR-.~freads 'test.csv'
+-+-+----------+-------+---+
|1|2|"embedded | comma"|3.4|
+-+-+----------+-------+---+
|5|6|"no comma"|7.8 | |
+-+-+----------+-------+---+
On Sat, Dec 7, 2013 at 10:27 AM, Brian Schott <[email protected]>wrote:
> It looks like there is a typo in command with `mat`: .; should be ;. .
> 'mat` is not a verb but a noun, btw.
> I think tilde is a dyadic tilde, not monadic and swaps the arguments of -.
> in this case.
>
> On Sat, Dec 7, 2013 at 9:08 AM, Jon Hough <[email protected]> wrote:
>
> > 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
> >
> >
> --
> (B=) <-----my sig
> Brian Schott
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Devon McCormick, CFA
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm