experchange > perl

Joe (10-22-19, 09:41 PM)
I am suing Statistics::R to do some statistics analysis jobs, and I can successfully run my codes. There is one line to import the raw data, like:

$R->send(q`x<-c(69,69,72,72,72,93,93,93,357,357,357,156,156,156) `);

It works fine. However, when I tried to dynamically feed these numbers I got all sorts of complains. eg.

$data = "69,69,72,72,72,93,93,93,357,357,357,156,156,1 56";

$R->send(q`x<-c($data)`);
ERROR: unexpected '$';

$R->send(q`x<-c("$data")`);
ERROR: "argument is not numeric"

etc. It seems the back tick is making problems here. Any suggestion I can get by with this?

Thanks in advance!

joe
Eli the Bearded (10-22-19, 10:03 PM)
In comp.lang.perl.misc, Joe <juliani.moon> wrote:
> It works fine. However, when I tried to dynamically feed these numbers I got all sorts of
> complains. eg.
> $data = "69,69,72,72,72,93,93,93,357,357,357,156,156,1 56";
> $R->send(q`x<-c($data)`);
> ERROR: unexpected '$';
> etc. It seems the back tick is making problems here. Any suggestion I can get by with this?


qX...X is a syntax for a single-quoted style string with arbitrary
delimiter. Single-quoted style strings do not do variable interpolation.

When you want to do that, use a double-quoted format, eg:

$R->send(qq`x<-c($data)`);

Elijah
------
so it wasn't the backtick but how the backtick was being used
Joe (10-22-19, 10:56 PM)
On Tuesday, October 22, 2019 at 3:03:25 PM UTC-5, Eli the Bearded wrote:
> In comp.lang.perl.misc, Joe wrote:
> qX...X is a syntax for a single-quoted style string with arbitrary
> delimiter. Single-quoted style strings do not do variable interpolation.
> When you want to do that, use a double-quoted format, eg:
> $R->send(qq`x<-c($data)`);
> Elijah
> ------
> so it wasn't the backtick but how the backtick was being used


Thank you Elijah! This helps me to review the basics of the basics 'qq', 'qw', qr', etc. and better understand of the original code with 'q' :-)

Joe
Keith Thompson (10-23-19, 12:24 AM)
Eli the Bearded <*> writes:
> In comp.lang.perl.misc, Joe <juliani.moon> wrote:
> qX...X is a syntax for a single-quoted style string with arbitrary
> delimiter. Single-quoted style strings do not do variable interpolation.


And the choice of ` as the quoting character is potentially confusing.

Without the "q", `blah` does command substitution (invoking the "blah"
command and expanding to its output). `blah` can also be written as
qx{blah}, or qx|blah| or ....

(Similarly, qq'blah' does variable interpolation, and q"blah" doesn't.)

> When you want to do that, use a double-quoted format, eg:
> $R->send(qq`x<-c($data)`);


or just

$R->send("x<-c($data)`);

or, more clearly IMHO

$R->send(qq{x<-c($data)});

[...]
$Bill (10-23-19, 04:32 AM)
On 10-22-19 15:24, Keith Thompson wrote:
> And the choice of ` as the quoting character is potentially confusing.


Totally - I wouldn't use it for anything but shelling a cmd and getting response
back into variable. $x = `cmd args`;

> Without the "q", `blah` does command substitution (invoking the "blah"
> command and expanding to its output). `blah` can also be written as
> qx{blah}, or qx|blah| or ....
> (Similarly, qq'blah' does variable interpolation, and q"blah" doesn't.)


Or more simply 'blah' doesn't and "blah" does - why bother with the q/qq.
Eric Pozharski (10-23-19, 08:24 AM)
with <ln1rv4e7vw.fsf> Keith Thompson wrote:
> Eli the Bearded <*> writes:
>> In comp.lang.perl.misc, Joe <juliani.moon> wrote:



Please provide complete minimal example that clearly demonstrates your
problem.

*SKIP*
> $R->send(qq{x<-c($data)});


C'mon you guys, you're better than this. "ERROR: ..." messages don't
come from perl. It should be something like

$R->send( $x->c($data) );

but something went terribly wrong.
Keith Thompson (10-24-19, 01:07 AM)
Eric Pozharski <whynot> writes:
> with <ln1rv4e7vw.fsf> Keith Thompson wrote:
> Please provide complete minimal example that clearly demonstrates your
> problem.
> *SKIP*
> C'mon you guys, you're better than this. "ERROR: ..." messages don't
> come from perl.


Right, it's from R. I don't think anyone said it was a Perl error
message.

> It should be something like
> $R->send( $x->c($data) );
> but something went terribly wrong.


This uses the Statistics::R module. I haven't used it myself, but I
believe the string that should be sent to the send() function is:

'x<-c(69,69,72,72,72,93,93,93,357,357,357,156,156,156) '

where the sequence of numbers is expanded from $data. It was written as

$R->send(q`x<-c($data)`);

but it should have been written as

$R->send(qq`x<-c($data)`);

or, more clearly, as

$R->send("x<-c($data)");

x and c appear to be R entities, not Perl entities. <- is the R
left assignment operator, not related to the Perl -> operator.

The documentation for Statistics::R uses qq`...` and q`...` literals in
its examples (see ). I don't know
why. I thought it might be an attempt to use a delimiter character
that's unlikely to appear in the string, but R uses the backtick in its
own syntax.

The problem in the original post was the use of q`...`. Using qq`...`
instead would fix the problem, but would still be unclear. Using qq
with a different delimiter, or just using "...", would also fix the problem
and would be clearer.
Eric Pozharski (10-24-19, 08:26 AM)
with <ln4kzzcb79.fsf> Keith Thompson wrote:
> Eric Pozharski <whynot> writes:


*SKIP*
> or, more clearly, as
> $R->send("x<-c($data)");
> x and c appear to be R entities, not Perl entities. <- is the R left
> assignment operator, not related to the Perl -> operator.


Ouch. Now I understand what went wrong.

> The documentation for Statistics::R uses qq`...` and q`...` literals
> in its examples (see ). I don't
> know why. I thought it might be an attempt to use a delimiter
> character that's unlikely to appear in the string, but R uses the
> backtick in its own syntax.


*If* S::R uses double-quotes too that might be bad taste of humor, like
if "left assignment" then "left quote".

*CUT*
Similar Threads