in reply to Undefined subroutine error while using R within Perl
G'day rkeshvardoost,
You have some questionable code here. Consider these two adjacent lines:
package R; package R::startR;
Are you missing some code that should come after package R;? If not, why did you use package R; in the first place?
The use lib 'R'; line seems to be in the wrong place in your code. Without knowing your directory structure, I can't even say if it's correct (regardless of its position).
In this part of your code:
package R::startR; ... @EXPORT_OK = qw(startR ...
that refers to R::startR::startR. Was that what you meant? If so, you haven't declared it!
At this point, I'm starting to have to make many guesses as to your actual intent. The following is how I might have written something that may be close to what you want.
Firstly, I created a directory (pm_1152700_libs) and populated it like this:
$ cat pm_1152700_libs/R.pm package R; use Exporter 'import'; our @EXPORT_OK = qw{startR}; sub startR { print 'This is &R::startR' } 1;
$ cat pm_1152700_libs/R/startR.pm package R::startR; use Exporter 'import'; our @EXPORT_OK = qw{startR}; sub startR { print 'This is &R::startR::startR' } 1;
I then wrote this test script (but do see the notes I've written afterwards):
#!/usr/bin/env perl -l use strict; use warnings; use lib 'pm_1152700_libs'; use R qw{startR}; use R::startR qw{startR}; R::startR(); R::startR::startR();
which outputs
This is &R::startR This is &R::startR::startR
You've used startR in both module and subroutine names. This is highly error-prone and I'd recommend you think of better names.
I've repeated the use of startR in both module and subroutine names; however, note the following:
use R qw{some_startR}; use R::startR qw{other_startR}; some_startR(); other_startR();
Finally, I strongly advise that you use the strict and warnings pragmata at the start of all your scripts.
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Undefined subroutine error while using R within Perl
by rkeshvardoost (Novice) on Jan 13, 2016 at 23:46 UTC | |
by kcott (Archbishop) on Jan 14, 2016 at 06:25 UTC |