Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Perl-R integration

by daverave (Scribe)
on Sep 25, 2010 at 19:29 UTC ( [id://861996]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl-R integration
in thread Perl-R integration

I guess the simplest thing I'd like to do is to pass a Perl array to R as a vector. Can I do that using Writer?

Replies are listed 'Best First'.
Re^3: Perl-R integration
by Khen1950fx (Canon) on Sep 26, 2010 at 04:19 UTC
    I think that these examples of simple initialization will get you going. I hope they help.

    To start:

    #!/usr/bin/perl use strict; use warnings; use R::Writer; my $R = R::Writer->new(); $R->var(y => $R->expression( 'a * x ^ 2' )); print $R->as_string(), "\n";
    And a little more:
    #!/usr/bin/perl use strict; use warnings; use R::Writer; my $R = R::Writer->new(); $R->var(x => $R->expression( 'a * x ^ 2' )); $R->var(y => $R->expression( 'a * x ^ 2' )); $R->call(c => \("x", "y")); print $R->as_string(), "\n";
      Unfortunately I can't install it. Failed both using cpanm and cpan. I'm not sure what is the problem. Here is the log:
      cpanm (App::cpanminus) 1.0012 on perl 5.010001 built for i486-linux-gn +u-thread-multi Work directory is /home/dave/.cpanm/work/1285489233.5207 You have make /usr/bin/make You have LWP 5.834 You have /bin/tar: tar (GNU tar) 1.22 Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gp +l.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by John Gilmore and Jay Fenlason. You have /usr/bin/unzip Searching R::Writer on cpanmetadb ... Fetching http://search.cpan.org/CPAN/authors/id/D/DM/DMAKI/R-Writer-0. +00001.tar.gz -> OK Unpacking R-Writer-0.00001.tar.gz Entering R-Writer-0.00001 Configuring R-Writer-0.00001 Running Makefile.PL *** Module::AutoInstall version 1.03 *** Checking for Perl dependencies... [Core Features] - Class::Accessor::Fast ...loaded. (0.34) - JSON::XS ...loaded. (2.29 >= 2.01) - Sub::Exporter ...missing. ==> Auto-install the 1 mandatory module(s) from CPAN? [y] y *** Since we're running under CPANPLUS, I'll just let it take care of the dependency's installation later. *** Module::AutoInstall configuration finished. Warning: prerequisite Sub::Exporter 0 not found. Checking if your kit is complete... Looks good Writing Makefile for R::Writer -> OK Finding PREREQ from Makefile ... Checking if you have Sub::Exporter 0 ... No Checking if you have JSON::XS 2.01 ... Yes (2.29) Checking if you have Class::Accessor::Fast 0 ... Yes (0.34) ==> Found dependencies: Sub::Exporter Searching Sub::Exporter on cpanmetadb ... Fetching http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/Sub-Exporter +-0.982.tar.gz -> OK Unpacking Sub-Exporter-0.982.tar.gz Entering Sub-Exporter-0.982 Configuring Sub-Exporter-0.982 Running Makefile.PL Warning: prerequisite Data::OptList 0.1 not found. Warning: prerequisite Params::Util 0.14 not found. Warning: prerequisite Sub::Install 0.92 not found. Checking if your kit is complete... Looks good Writing Makefile for Sub::Exporter -> OK Finding PREREQ from Makefile ... Checking if you have Params::Util 0.14 ... No Checking if you have Sub::Install 0.92 ... No Checking if you have ExtUtils::MakeMaker 6.55 ... Yes (6.55_02) Checking if you have Data::OptList 0.1 ... No ==> Found dependencies: Params::Util, Sub::Install, Data::OptList Searching Params::Util on cpanmetadb ... Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Params-Util +-1.01.tar.gz -> OK Unpacking Params-Util-1.01.tar.gz Entering Params-Util-1.01 Checking if you have ExtUtils::MakeMaker 6.42 ... Yes (6.55_02) Configuring Params-Util-1.01 Running Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for Params::Util -> OK Finding PREREQ from Makefile ... Checking if you have Test::More 0.42 ... Yes (0.92) Checking if you have Scalar::Util 1.18 ... Yes (1.21) Checking if you have File::Spec 0.80 ... Yes (3.30) Building and testing Params-Util-1.01 for Params::Util cp lib/Params/Util.pm blib/lib/Params/Util.pm /usr/bin/perl /usr/local/share/perl/5.10.1/ExtUtils/xsubpp -typemap / +usr/share/perl/5.10/ExtUtils/typemap Util.xs > Util.xsc && mv Util.x +sc Util.c cc -c -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe + -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_O +FFSET_BITS=64 -O2 -g -DVERSION=\"1.01\" -DXS_VERSION=\"1.01\" -fPIC + "-I/usr/lib/perl/5.10/CORE" -DPERL_EXT Util.c Running Mkbootstrap for Params::Util () chmod 644 Util.bs rm -f blib/arch/auto/Params/Util/Util.so cc -shared -O2 -g -L/usr/local/lib -fstack-protector Util.o -o blib/ +arch/auto/Params/Util/Util.so \ \ chmod 755 blib/arch/auto/Params/Util/Util.so cp Util.bs blib/arch/auto/Params/Util/Util.bs chmod 644 blib/arch/auto/Params/Util/Util.bs Manifying blib/man3/Params::Util.3pm PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib/lib', 'blib/arch')" t/*.t t/01_compile.t .... ok t/02_main.t ....... ok t/03_all.t ........ ok t/04_codelike.t ... ok t/05_typelike.t ... ok t/06_invocant.t ... ok t/07_handle.t ..... ok t/08_driver.t ..... ok t/09_insideout.t .. ok t/11_compile.t .... ok t/12_main.t ....... ok t/13_all.t ........ ok t/14_codelike.t ... ok t/15_typelike.t ... ok t/16_invocant.t ... ok t/17_handle.t ..... ok t/18_driver.t ..... ok t/19_insideout.t .. ok All tests successful. Files=18, Tests=1654, 0 wallclock secs ( 0.19 usr 0.01 sys + 0.63 c +usr 0.05 csys = 0.88 CPU) Result: PASS Files found in blib/arch: installing files in blib/lib into architectu +re dependent library tree Installing /usr/local/lib/perl/5.10.1/auto/Params/Util/Util.so Installing /usr/local/lib/perl/5.10.1/auto/Params/Util/Util.bs Installing /usr/local/lib/perl/5.10.1/Params/Util.pm Installing /usr/local/man/man3/Params::Util.3pm Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.po +d -> OK Successfully installed Params-Util-1.01 Searching Sub::Install on cpanmetadb ... Fetching http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/Sub-Install- +0.925.tar.gz -> OK Unpacking Sub-Install-0.925.tar.gz Entering Sub-Install-0.925 Checking if you have ExtUtils::MakeMaker 0 ... Yes (6.55_02) Configuring Sub-Install-0.925 Running Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for Sub::Install -> OK Finding PREREQ from Makefile ... Checking if you have Test::More 0 ... Yes (0.92) Checking if you have Scalar::Util 0 ... Yes (1.21) Building and testing Sub-Install-0.925 for Sub::Install cp lib/Sub/Install.pm blib/lib/Sub/Install.pm Manifying blib/man3/Sub::Install.3pm PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib/lib', 'blib/arch')" t/*.t # Testing Sub::Install 0.925 t/00-load.t ....... ok t/auto_as.t ....... ok t/export.t ........ ok t/inst-blessed.t .. ok t/install.t ....... ok t/misc_errors.t ... ok t/perl-critic.t ... skipped: define PERL_TEST_CRITIC to run these test +s t/pod-coverage.t .. skipped: Test::Pod::Coverage 1.06 required for tes +ting POD coverage t/pod.t ........... skipped: Test::Pod 1.14 required for testing POD t/reinstall.t ..... ok t/SI_install.t .... ok t/SI_reinstall.t .. ok All tests successful. Files=12, Tests=65, 1 wallclock secs ( 0.04 usr 0.00 sys + 0.22 cus +r 0.00 csys = 0.26 CPU) Result: PASS Manifying blib/man3/Sub::Install.3pm Installing /usr/local/share/perl/5.10.1/Sub/Install.pm Installing /usr/local/man/man3/Sub::Install.3pm Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.po +d -> OK Successfully installed Sub-Install-0.925 Searching Data::OptList on cpanmetadb ... Fetching http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/Data-OptList +-0.106.tar.gz -> OK Unpacking Data-OptList-0.106.tar.gz Entering Data-OptList-0.106 Checking if you have ExtUtils::MakeMaker 6.42 ... Yes (6.55_02) Configuring Data-OptList-0.106 Running Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for Data::OptList -> OK Finding PREREQ from Makefile ... Checking if you have List::Util 0 ... Yes (1.21) Checking if you have Params::Util 0.14 ... Yes (1.01) Checking if you have Sub::Install 0.921 ... Yes (0.925) Checking if you have ExtUtils::MakeMaker 6.42 ... Yes (6.55_02) Building and testing Data-OptList-0.106 for Data::OptList cp lib/Data/OptList.pm blib/lib/Data/OptList.pm Manifying blib/man3/Data::OptList.3pm PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'inc', 'blib/lib', 'blib/arch')" t/*.t t/hash.t ... ok t/mkopt.t .. ok All tests successful. Files=2, Tests=32, 0 wallclock secs ( 0.01 usr 0.01 sys + 0.06 cusr + 0.00 csys = 0.08 CPU) Result: PASS Manifying blib/man3/Data::OptList.3pm Installing /usr/local/share/perl/5.10.1/Data/OptList.pm Installing /usr/local/man/man3/Data::OptList.3pm Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.po +d -> OK Successfully installed Data-OptList-0.106 Building and testing Sub-Exporter-0.982 for Sub::Exporter cp lib/Sub/Exporter/Util.pm blib/lib/Sub/Exporter/Util.pm cp lib/Sub/Exporter/Cookbook.pod blib/lib/Sub/Exporter/Cookbook.pod cp lib/Sub/Exporter/Tutorial.pod blib/lib/Sub/Exporter/Tutorial.pod cp lib/Sub/Exporter.pm blib/lib/Sub/Exporter.pm Manifying blib/man3/Sub::Exporter::Util.3pm Manifying blib/man3/Sub::Exporter::Cookbook.3pm Manifying blib/man3/Sub::Exporter::Tutorial.3pm Manifying blib/man3/Sub::Exporter.3pm /usr/bin/perl "-Iinc" "-MModule::Install::ExtraTests" "-e" "Module::In +stall::ExtraTests::__harness('Test::Harness', 0, '', 'xt/release', '' +, 0, 'blib/lib', 'blib/arch')" t/*.t t/col-init.t .............. ok t/collection.t ............ ok t/expand-group.t .......... ok t/faux-export.t ........... ok t/gen-callable.t .......... ok t/group-generator.t ....... ok t/inherited.t ............. ok t/into-level.t ............ ok t/real-export-groupgen.t .. ok t/real-export-href.t ...... ok t/real-export-setup.t ..... ok t/util-curry.t ............ ok t/util-currychain.t ....... ok t/util-like.t ............. ok t/util-merge.t ............ ok t/util-mixin.t ............ skipped: the mixin exporter requires Packa +ge::Generator t/util-namemap.t .......... skipped: not actually offerring this featu +re yet t/valid-config.t .......... ok All tests successful. Files=18, Tests=249, 0 wallclock secs ( 0.06 usr 0.01 sys + 0.49 cu +sr 0.06 csys = 0.62 CPU) Result: PASS Installing /usr/local/share/perl/5.10.1/Sub/Exporter.pm Installing /usr/local/share/perl/5.10.1/Sub/Exporter/Tutorial.pod Installing /usr/local/share/perl/5.10.1/Sub/Exporter/Util.pm Installing /usr/local/share/perl/5.10.1/Sub/Exporter/Cookbook.pod Installing /usr/local/man/man3/Sub::Exporter.3pm Installing /usr/local/man/man3/Sub::Exporter::Cookbook.3pm Installing /usr/local/man/man3/Sub::Exporter::Util.3pm Installing /usr/local/man/man3/Sub::Exporter::Tutorial.3pm Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.po +d -> OK Successfully installed Sub-Exporter-0.982 Building and testing R-Writer-0.00001 for R::Writer /usr/bin/perl "-Iinc" Makefile.PL --config= --installdeps=Sub::Exporte +r,0 cp lib/R/Writer/Var.pm blib/lib/R/Writer/Var.pm cp lib/R/Writer/Call.pm blib/lib/R/Writer/Call.pm cp lib/R/Writer.pm blib/lib/R/Writer.pm cp lib/R/Writer/Range.pm blib/lib/R/Writer/Range.pm cp lib/R/Writer/Encoder.pm blib/lib/R/Writer/Encoder.pm Manifying blib/man3/R::Writer::Call.3pm Manifying blib/man3/R::Writer::Var.3pm Manifying blib/man3/R::Writer::Range.3pm Manifying blib/man3/R::Writer.3pm Manifying blib/man3/R::Writer::Encoder.3pm /usr/bin/perl "-Iinc" Makefile.PL --config= --installdeps=Sub::Exporte +r,0 PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'inc', 'blib/lib', 'blib/arch')" t/01_load.t t/02_simple.t +t/03_assign.t t/04_function.t t/05_reset.t t/06_save.t t/99_pod-cover +age.t t/99_pod.t t/01_load.t .......... ok t/02_simple.t ........ ok t/03_assign.t ........ ok t/04_function.t ...... ok t/05_reset.t ......... ok # Looks like you planned 14 tests but ran 12. t/06_save.t .......... Dubious, test returned 255 (wstat 65280, 0xff00) Failed 2/14 subtests (less 2 skipped subtests: 10 okay) t/99_pod-coverage.t .. skipped: Enable TEST_POD environment variable t +o test POD t/99_pod.t ........... skipped: Enable TEST_POD environment variable t +o test POD Test Summary Report ------------------- t/06_save.t (Wstat: 65280 Tests: 12 Failed: 0) Non-zero exit status: 255 Parse errors: Bad plan. You planned 14 tests but ran 12. Files=8, Tests=26, 0 wallclock secs ( 0.04 usr 0.00 sys + 0.19 cusr + 0.02 csys = 0.25 CPU) Result: FAIL Failed 1/8 test programs. 0/26 subtests failed. make: *** [test_dynamic] Error 255 -> FAIL Installing R::Writer failed. See /home/dave/.cpanm/build.log f +or details.
        Since you only failed 1 of 8 tests, go ahead and use cpan to force install. I had a similar problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://861996]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found