barabasi has asked for the wisdom of the Perl Monks concerning the following question:

My problem is not in PERL, I am seeking for wisdom of PERL Monks to solve a problem in igraph package of R software. Any PERL MONK with knowledge of other languages such as R, can help me out. You can even suggest me links, where I could find a solution
My problem is..
I want to plot a power law fit for my data (in .net format --- pajek format)
syntax for that in R is
g <- read.graph("filename.net", "pajek")
d <- degree (g, mode="in")
power.law.fit (d+1, 2)
it gives me desired out put if my if input a single file
but I want to use a variable file name ( such as $name1,
$name2 in PERL) so that I can read all my 100 files at a
single stretch if I put this entire code in a loop like..
names = "name1" "name2" "name3".....
while (i <= 100)
g <- read.graph("namesi", "pajek")
d <- degree (g, mode="in")
power.law.fit (d+1, 2)
i <- i + 1
}
but namesi doesn't seem to work in R. Is there any alternative ?
I want to know how to use a variable file name in this syntax
Any help is greatly appreciated
barabasi
  • Comment on Need Wisdom of Perlmonks to solve my problem in R software

Replies are listed 'Best First'.
Re: Need Wisdom of Perlmonks to solve my problem in R software
by almut (Canon) on May 13, 2010 at 19:05 UTC

    You could also try Statistics::R to control your R interpreter from Perl, i.e. you'd create the command strings on the Perl side and use $R->send($cmd) to execute them.  Something like this:

    use Statistics::R; my $R = Statistics::R->new(); $R->startR; for my $i (1..100) { $R->send( << "EOR"; g <- read.graph("filename$i.net", "pajek") d <- degree (g, mode="in") power.law.fit (d+1, 2) EOR )}
Re: Need Wisdom of Perlmonks to solve my problem in R software
by CountZero (Bishop) on May 13, 2010 at 18:57 UTC
    A Perlish solution would be to write a Perl script that writes an R-source file for you. That R-source file can then be used from within R using the source("my_source.R") function if working interactively, or R CMD BATCH my_source.R if running as a batch from the command-line.

    Or you could try R::Writer (warning: it is still in alpha).

    Oh, and BTW, it is "Perl" (the language) or "perl" (the interpreter), but never ever "PERL".

    Update: added link to R::Writer

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Need Wisdom of Perlmonks to solve my problem in R software
by toolic (Bishop) on May 13, 2010 at 18:02 UTC