Passing a script as a parameter to RGui

I was wondering if it is possible to pass parameters to RGui from the command line in Windows. I would like to do something like

RGui myScript.r param1 param2

just as I would do with RScript, but I need to display a graphical interface.

Here is more information about my needs. I want to insert gui written in R in my C # forms application. What would happen, I press a button in the form, and the application starts a process that calls RGui with my script and some parameters. So far this has worked well with RScript, but now that I am showing the graphics, I need R to be interactive. Here is the code I'm using:

        myProcess.StartInfo.FileName =Pathing.GetUNCPath( r_path) + "\\Rscript";
        string script_path=Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent.FullName.ToString();
        myProcess.StartInfo.Arguments = Pathing.GetUNCPath(script_path) + "\\display.r " + data_path;
        myProcess.StartInfo.UseShellExecute = true;           
        myProcess.Start();
        myProcess.WaitForExit();
+5
source share
2 answers

, . Rprofile Rprofile.site (. " " ), , . , , .

Rprofile Rprofile.site ( /etc R):

Args <- commandArgs(trailingOnly=TRUE)
if(length(Args)>0 & sum(grepl(" -f ",commandArgs()))==0 ){          
    if(grepl("(?i).r$",Args[1])){
        File <- Args[1]
        Args <- Args[-1]
        tryCatch(source(File) , error=function(e) print(e) )
    }
}

:

Rgui --args myscript.r arg1 arg2
Rscript myscript.r arg1 arg2
R --args myscript.r arg1 arg2
R -f myscript.r --args arg1 arg2

-args , @iterator. Args, ( .GlobalEnv!). , . script, :

#dumb script
print(Args)

Rgui R, File, , .

, rProfile . . -f --args, .

: "-f", "-f", "path/to/new-files/".

+7

() : "", . , Rgui script. @Joris , Rgui --help.

, , . , , . , , .

.

script .Rprofile, . .Rprofile ( ), commandArgs(), .

/ R. , .

, Rstudio: http://support.rstudio.org/help/discussions/problems/823-pass-command-line-parameters-to-r

+3

All Articles