- SEE ALSO
- COPYRIGHT AND LICENSE
Statistics::NiceR - interface to the R programming language
use Statistics::NiceR; my $r = Statistics::NiceR->new(); say $r->pnorm( [ 0 .. 3 ] ) # [0.5 0.84134475 0.97724987 0.9986501]
This module provides an interface to the R programming language for statistics by embedding the R interpreter using its C API. This allows direct access to R's functions and allows sending and receiving data efficiently.
In order to give the module a hassle-free interface, there is a mechanism to convert Perl types[^1] to R types[^2] and vice-versa for the values sent to and from the R interpreter.
Currently, the conversion is handled by the modules under the Statistics::NiceR::DataConvert namespace. It is currently undocumented how to extend this to more types or how to change the default behaviour, but this will be addressed in future versions.
[^1]: Such as strings, numbers, and arrays.
[^2]: Such as integers, numerics, data frames, and matrices.
Creates a new instance of a wrapper around the R interpreter.
use Statistics::NiceR; my $r = Statistics::NiceR->new();
eval_parse( Str $r_code )
A convenience function that allows for evaluating arbitrary R code.
The return value is the last line of the code in
use Statistics::NiceR; my $r = Statistics::NiceR->new(); my $dataframe = $r->eval_parse( q< iris[1:20,1:4] > );
R functions can be called by using the name of the function as a method call. For example, to call the pnorm function (PDF of the normal distribution), which has the R function signature
pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
one could run
use Statistics::NiceR; my $r = Statistics::NiceR->new(); say $r->pnorm( 0 ) # N( μ = 0, σ² = 1) at x = 0 # 0.5 say $r->pnorm( 5, 1, 2 ) # N( μ = 1, σ² = 2) at x = 5 # 0.977249868051821
Since R can have identifiers that contain a period (".") in their name and Perl can not,
a single underscore in the Perl function name ("_") to a period in the R function name (".")
two consecutive underscores in the Perl function name ("__") to a single underscore in the R function name ("_").
So in order to call R's
as.Date function, one could run:
use Statistics::NiceR; my $r = Statistics::NiceR->new(); say $r->as_Date( "02/27/92", "%m/%d/%y" ); # one underscore #  "1992-02-27"
or to call R's
l10n_info function, one could run:
use Statistics::NiceR; my $r = Statistics::NiceR->new(); say $r->l10n__info(); # two underscores # $MBCS #  TRUE # # $`UTF-8` #  TRUE # # $`Latin-1` #  FALSE
On a system with a package manager, it would be best to install the R base package using the package manager.
Browse and download additional R packages: The Comprehensive R Archive Network
Zakariyya Mughal <email@example.com>
This software is copyright (c) 2014 by Zakariyya Mughal.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.