Skip to content
Prev 349807 / 398513 Next

script works in Rstudio but not with Rscript

OK, this suggestion brings up some interesting results.  No solution,
however.  But it's interesting ... and maybe some helpful leads.

The basic/short answer to your question is no, it doesn't work with "R
-f script".

The longer answer: Note that the script is currently set up to be
called with a command line argument, "./affinity_propagation.R 3".  So
first I tried "R -f affinity_propagation.R 3".  That failed, but
because it wasn't using the "3" as an argument.  So I modified the
code to hard-code the value 3 in there and not read the command line
argument using commandArgs(TRUE).  Then I ran the script using
"./affinity_propagation.R" -- and it worked!  "R -f
affinity_propagation.R" also worked.

Then I noticed the --args command line option for R, and I ran "R -f
affinity_propagation.R --args 3" on the original script, and it
failed, the same error as I described below.

Also, when you say "Try loading methods", do you mean just a line like
the following?:

library(methods)

I tried that as well, and it didn't help, same error.

So, given all that, any new ideas?  Is the call to commandArgs()
screwing something up?  Can that be fixed somehow?  Is there another
library/function I could/should use to read command line arguments?

Hmmm, playing around with things some more, it looks like if I do:

num <- as.integer(args[1])

rather than:

num <- args[1]

things work.  So maybe this is an issue with types, scalar vs. array,
number vs. string?

Milt Epstein
Programmer in Computational Genomics
Institute for Genomic Biology (IGB)
University of Illinois at Urbana-Champaign (UIUC)
mepstein at illinois.edu
On Wed, 8 Apr 2015, Henrik Bengtsson wrote: