[R] perl module for R

Duncan Temple Lang duncan at wald.ucdavis.edu
Mon Nov 5 23:37:23 CET 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Lux Zhang wrote:
> On 06/11/2007, Adrian Dusa <dusa.adrian at gmail.com> wrote:
>> On Monday 05 November 2007, you wrote:
>>> On 04/11/2007, Andrew Perrin <clists at perrin.socsci.unc.edu> wrote:
>>>> http://www.omegahat.org/RSPerl/
>>>>
>>>> ----------------------------------------------------------------------
>>>> Andrew J Perrin - andrew_perrin (at) unc.edu -
>>>> http://perrin.socsci.unc.edu
>>>> Associate Professor of Sociology; Book Review Editor, _Social Forces_
>>>> University of North Carolina - CB#3210, Chapel Hill, NC 27599-3210 USA
>>> hi, can some one convert this R command into perl for me?
>>>
>>> layout(matrix(1,2,3,4,5,6), 2,3, byrow=TRUE)
>>
>> I don't think anyone can possibly translate it into Perl (or in any other
>> language), simply because your command is faulty.
>> What are you trying to achieve:
>> - produce a matrix, or
>> - create a graphics device split into rows and columns?
>>
>> Either way, your matrix command is wrong, eg:
>> matrix(c(1,2,3,4,5,6), 2, 3, byrow=TRUE)
>>       ^^^
>> (notice the c() function)
> 
> 
> thanks, that was a typo.
> What I want to to convert
> layout(matrix(c(1,2,3,4), 2,2,, byrow=TRUE) ) to a perl code.
> 
> I tried it as
> &R::call ("layout", "(matrix(c(1,2,3), 1,3, byrow=TRUE))" );
> 
> It is not working.
> 
> BUT the following is working
> 
> &R::eval ("layout (matrix(c(1,2,3), 1,3, byrow=TRUE))" );


The RSPerl interface is designed to allow the Perl programmer
to avoid the R syntax and to make calls to R functions in the
Perl style, managing variables in Perl rather than in both Perl
and R's namespace.
That said, since you want to evaluate an R expression
you can call an R function which takes that R command
as a string and both parses it and evaluates the expression.

So
&R::parseEval("layout(matrix(c(1,2,3,4), 2,2,, byrow=TRUE) )");

will do it.

Or if you want to use the function invocation mechanism,

  R::layout(R::matrix([1, 3, 2, 4], 2, 2))

(or something close...)

Note that the 1, 2, 3, 4 are coming from a Perl array (if that is the
correct Perl syntax for an array)

I reorganized the elements to simplify the example as specifying an R
argument by name (i.e. byrow) in Perl is annoying as Perl does not have
named arguments.





> 
> The R Call involves 3 layers of R function c(), matrix() and layout(). The
> essential question is how to implement the R functions in a logical order
> into perl?
> 
> Hope some one can exmplify this.
> 
> 
> 
> 
> 
> Adrian
>> --
>> Adrian Dusa
>> Romanian Social Data Archive
>> 1, Schitu Magureanu Bd
>> 050025 Bucharest sector 5
>> Romania
>> Tel./Fax: +40 21 3126618 \
>>           +40 21 3120210 / int.101
>>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHL5sj9p/Jzwa2QP4RAt6JAJwNmHZspWmBDgs82vO6j5/9lmxdTwCfXK0f
UUsUvQlPFhLUXoIOSgCo/zU=
=bfk8
-----END PGP SIGNATURE-----



More information about the R-help mailing list