Skip to content
Prev 384122 / 398502 Next

iterators : checkFunc with ireadLines

Hi Laurent,

Off the bat I would have guessed that the problem you're seeing has to
do with 'command line quoting' differences between the Windows system
and the Linux/Mac systems. I've noticed people using Windows having
better command line success with "exterior double-quotes / interior
single-quotes" while Linux/Mac tend to have more success with
"exterior single- quotes / interior double-quotes". The problem is
exacerbated in R by system() or pipe() calls which require another
(exterior) set of quotations.

1. You can print out your connection object to make sure that the
interior code was read properly into R. Also, take a look at the
'connections' help page to see if there are other parameters you need
to explicitly set (like encoding). Here's the first (working) example
from my last post to you:
description
"raku -e '.put for lines.grep( / ^^N053 | ^^N163 /, :p );'  Laurents.txt"
                                                                    class
                                                                   "pipe"
                                                                     mode
                                                                     "rt"
                                                                     text
                                                                   "text"
                                                                   opened
                                                                 "opened"
                                                                 can read
                                                                    "yes"
                                                                can write
                                                                     "no"
2. You can try 'backslash-escaping' interior quotes in your system()
or pipe() calls. Also, in two of my previous examples I use paste() to
break up complicated quoting into more manageable chunks. You can try
these calls with 'backslash-escaped' interior quotes, and without
paste():
description
"raku -e '.put for lines.grep( / ^^N053 | ^^N163 /, :p );' Laurents.txt"
                                                                   class
                                                                  "pipe"
                                                                    mode
                                                                    "rt"
                                                                    text
                                                                  "text"
                                                                  opened
                                                                "opened"
                                                                can read
                                                                   "yes"
                                                               can write
                                                                    "no"
3. If R creates your 'con_obj' without throwing an error, then you
should try the most basic functions for reading data into R, something
like readLines(). Again, recreate our 'con_obj' with different
encodings, if necessary. Be careful of reading from the same
connection object with multiple R functions (an unlikely scenario, but
one that should be mentioned). Below it appears that 'con_obj1' gets
consumed by readLines() before the second call to scan():
Error in scan(con_obj1) : scan() expected 'a real', got 'N053'
[1] "N053    -0.014083    -0.004741    0.001443    -0.010152 -0.012996
   -0.005337    -0.008738    -0.015094    -0.012104"
[2] "N163    -0.054023    -0.049345    -0.037158    -0.04112 -0.044612
   -0.036953    -0.036061    -0.044516    -0.046436"
Read 0 items
numeric(0)
Other than that, you can post here again and we'll try to help. If you
become convinced it's a raku problem, you can check the 'raku-grep'
help page at https://docs.raku.org/routine/grep, or post a question to
the perl6-users mailing list at perl6-users at perl.org .

HTH, Bill.

W. Michels, Ph.D.
On Wed, May 27, 2020 at 1:56 AM Laurent Rhelp <LaurentRHelp at free.fr> wrote: