From dmurdoch at pair.com  Tue Apr 13 17:31:53 2004
From: dmurdoch at pair.com (Duncan Murdoch)
Date: Tue Apr 13 17:31:55 2004
Subject: [Rd] Re: [R] Execute function at startup
In-Reply-To: <407BF7AD.2050506@univie.ac.at>
References: <407BF7AD.2050506@univie.ac.at>
Message-ID: <tn0o70lutaaj3mk2216ltaees6svcugpms@4ax.com>

As far as I know what you're asking for doesn't exist, so I've moved
this discussion to r-devel.

On Tue, 13 Apr 2004 16:22:37 +0200, Erich Neuwirth
<erich.neuwirth@univie.ac.at> wrote :

>It would be convenient to have something like
>Rgui runfist="myfunction()"
>in Windows.

That looks as though you're creating an environment variable named
"runfist".  I'd rather use some different syntax than that...

>The reason:
>AFAIK Rgui does not accept piped input
>(RGui < myfile.R does not seem to work).

That would be hard to implement, as most people start Rgui using a
shortcut, and shortcuts don't support I/O redirection.

However, I think it would be useful to be able to source a file
somehow.  I can see a couple of different possibilities:

Rgui --exec source('myfile.R')

or 

Rgui --source myfile.R

The semantics would be that the code is executed after all other
initialization is done (profile executed, user's saved image restored,
etc.), just as if it had been typed in the console.  When it's done,
control returns to the console (unless there's a q() in the commands).

>A solution could be to put a few fuctions in Rprofile and then
>give the name for one of these functions to be executed at startup as
>a command line parameter to Rgui.
>
>Can something like this be done?

Not now, but I think we should have something like this for 2.0.0.
There's already been some discussion about whether the bug fix to
.Profile is desirable (it's now run before most packages are
attached).  It makes sense to me to have a way of running code there,
and also to have a way to run code just before the system gives
control to the user.  

Duncan Murdoch


[Rd] Re: [R] Execute function at startup
Duncan Murdoch