views:

221

answers:

3

I try this command :

Rscript "/Users/test/Scripts/arg_test.R" "path_in=/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Description.csv" path_in2="/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv"

but I have this error : Error in parse(text = args[[i]]) : unexpected '/' in "path_in=/"

Part of Rscript :

args=(commandArgs(TRUE))

if(length(args)==0){
    print("No arguments supplied.")
}else{
    for(i in 1:length(args)){
         eval(parse(text=args[[i]]))
    }
}


path_out = "/Users/test/Rproject/Results/"

annotation = read.csv(paste(path_in, sep=""))

modules = read.csv(paste(path_in2, sep=""))

merge_output = merge(annotation, modules, by = "Module")

How can I define path_in as argument(args) ?

Thank you.

A: 

You have path_in= inside the double quotes, but path_in2= outside. Could this be the problem?

Dennis Williamson
+1  A: 

Replacing the = with the proper assignment operator <- and protecting each argument with single quotes works for me:

Rscript /tmp/RscriptArgs.R  \
  'path_in<-"/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Description.csv"'  \
  'path_in2<-"/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv"'

where /tmp/RscriptArgs.R is what you showed from your script.

Dirk Eddelbuettel
A: 

Thank you, I just fix my problem !

I should use "path_in='/Users/test/...'" and not "path_in=/Users/test/...". Works fine with quote.

Rscript "/Users/test/Scripts/arg_test.R" "path_in='/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Gene-level Description for Modules.csv'" "path_in2='/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv'"

Fix add by Dirk works fine too (thanks) !

Fabien Barbier
Good to see you have it fixed. It is typical for someone who asked a question to then 'accept' an applicable answer, if one is given, rather than to provide another answer. So you may want to pick one here.
Dirk Eddelbuettel
I choose your fix (just add my fix to add another way to correct this bug).
Fabien Barbier
Merci bien --- And I didn't even suggest littler as an Rscript replacement ;-)
Dirk Eddelbuettel