Passing an array as an argument from a Perl script to a R script -


i new r , have perl script in want call r script, calculates me (not important in context). want give arguments input file, array contains numbers , number total number of clusters. medoid.r name of r script.

    $r_out;     $r_out = qx{./script/medoid.r $output @cluster $number_of_clusters} 

my current r code looks this. right print cluster see inside.

    args <- commandargs(true)     filename = args[1]     cluster = as.vector(args[2])     number_of_cluster = args[3]      matrix = read.table(filename, sep='\t', header=true, row.names=1, quote="")     print(cluster) 

is possible give array argument? how can save in r? right first number of array stored , printed, have every number in vector or similar.

in perl, qx expect string argument. may use array generate string, still string. cannot "pass array" system call, can pass command-line text/arguments.

keep in mind, executing system call running rscript child process. way you're describing issue, there no inter-process communication beyond command line. think of way: how type array on command line? may have textual way of representing array, can't type array on command line. arrays stored , accessed in memory differently various different languages, , not portable between 2 languages you're suggesting.

one solution: said, there may simple solution you. haven't provided information on type of data want pass in array. if simple enough, may try passing on command line delimited text, , break use in rscript.

here rscript shows mean:

args = commandargs(trailingonly=true) filename = args[1] cluster <- c(strsplit(args[2],"~"))  sprintf("filename: %s",filename) sprintf("cluster list: %s",cluster)  print("cluster:") cluster  sprintf("first item: %s",cluster[[1]][1]) 

save "test.r" , try executing "rscript test.r test.txt one~two" , you'll following output (tested on rscript 46084, openbsd):

[1] "filename: test.txt" [1] "cluster list: c(\"one\", \"two\")" [1] "cluster:" [[1]] [1] "one" "two"  [1] "first item: one" 

so, you'd have on perl side of things join() array using "~" or other delimiter- highly dependent on data, , haven't provided it.

summary: re-think how want communicate between perl , rscript. consider sending data delimited string (if it's right size) , breaking on other side. ipc if won't work, consider environment variables or other options. there no way send array reference on command-line.

note: may want read on security risks of different system calls in perl.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -