How to remove quotes folowing variable interpolation in Run() command?


I try to use Julia to start and existing R software. But I have problems because I dont know how to remove extra quotes added by variable interpolation.

Thanks !

See example here (it is a toy example, I have a much more complex command line in reality, with many arguments)

julia> files = "f1.txt"

julia> cmd = `R --vanilla --args $files`
`R --vanilla --args f1.txt` # this is good !

julia> files = join(["f1.txt", "f2.txt"], " ")
"f1.txt f2.txt"

julia> cmd = `R --vanilla --args $files`
`R --vanilla --args 'f1.txt f2.txt'` # this command fail because of the quotes around 'f1.txt f2.txt'
# how can I obtain `R --vanilla --args f1.txt f2.txt` ?

Not sure what you’re trying to do ultimately, but have you considered RCall.jl?

@nilshg thank you for your answer. Ultimately I want to replace a graphical interface by a command line utility in Julia.

cmd = `R --vanilla --args $var1 $var2 ... $varn`
run(pipeline("Rsoft.r", cmd))

I know Rcall but the R program I use is not directlty compatible with Rcall that is why I prefer to send arguments to the R program.

It is very unclear why thoses extra-quotes appears when the $files variable is build with join().

Just don’t join them yourself:

julia> files = ["f1.txt", "f2.txt"]
2-element Array{String,1}:

julia> cmd = `R --vanilla --args $files`
`R --vanilla --args f1.txt f2.txt`

See the docs here for more on how interpolating works with command objects.

1 Like

@ericphanson, simple and efficient solution, many thanks !

1 Like