Fabien Barbier
Fabien Barbier

Reputation: 1524

Rscript: Define path file as argument

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.

Upvotes: 1

Views: 1510

Answers (3)

Fabien Barbier
Fabien Barbier

Reputation: 1524

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) !

Upvotes: 0

Dirk is no longer here
Dirk is no longer here

Reputation: 368639

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.

Upvotes: 1

Dennis Williamson
Dennis Williamson

Reputation: 360693

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

Upvotes: 0

Related Questions