[R] Calling r-scripts with arguments from other scripts, or possibly R programming conventions/style guide
er|cjberger @end|ng |rom gm@||@com
Wed Jun 13 09:09:21 CEST 2018
I use the littler package for scripting. You may find it meets your needs.
On Wed, Jun 13, 2018 at 5:33 AM, Sam Tuck <STuck using nzsuperfund.co.nz> wrote:
> Hi All,
> I am new to R and am wondering if there is a way to pass
> arguments between rscripts. I have this working but have had to create a
> C# shell calling the scripts in sequence via windows scripting which
> enables command line arguments to get the necessary interaction.
> I'm wondering if I'm using an outdated program construction technique - I
> create r files like I would programme functions or reoccurring code
> snippets in C. It may be that r was not designed to create lots of little
> r script modules that interact via a master script?
> Ideally I'd like to call r scripts from other r scripts and have all the
> variables still in memory: For example
> I've been using RStudio Version 1.1.447 to programme and regression test
> my individual scripts,.
> Script Arg Script.R
> # We are going to pass arguments into this script
> arguments <- commandArgs(trailingOnly = TRUE)
> #arguments is double
> #arguments is double
> #arguments is double.
> if(length(arguments) <3)
> stop("Not enough arguments, please supply 3, [% dbl}total deviation, [%
> dbl] individual deviation, [int] periods before recenter")
> TotalDeviation <- as.numeric(arguments)/100
> IndividualDeviation <- as.numeric(arguments)/100
> RecenterPeriods <- as.numeric(arguments)
> # We then manipulate some objects based on these inputs, but for this test
> we will output them to a file.
> writeLines(c(TotalDeviation, IndividualDeviation, RecenterPeriods),
> Script RunningScript.R
> Arg Script.R 0.6 0.4 132
> To which I get
> Error: unexpected symbol in " Arg Script.R"
> When I use the script RunningScript.R
> system(paste("Arg Script.R", 0.8, 0.4, 132))
> Nothing occurs (there is no output file created, but also no error)
> When I use RunningScript.R
> commandArgs <- c(0.6,0.4,132)
> source("Arg Script.R')
> I don't get any args passed into the file. Instead getting the error
> Not enough arguments, please supply 3, [% dbl}total deviation, [% dbl]
> individual deviation, [int] periods before recenter
> Sam Tuck
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help