Hi! I've made great progress in my R programming, but I am again stuck on a beginner's problem. I would like to start R with a command line that loads a file, and if possible, executes a function. Can anyone give me an example of how to do this? For example, in lisp, I would say: $ lisp -load toto.lisp -eval '(do-something $PORT)' to load the file "toto.lisp", then evaluate the expression with the shell envt variable bound properly. I'd like to do this in R, but can't figure it out! Thanks, GF. [[alternative HTML version deleted]]
Hi! Thanks for your reply. Indeed, I'm on Linux. I tried to do what you said, but nothing happened. I made a file called First.R in my work directory. It contains this code .First<-function(){ source("First.R") source("client.r") cat("it worked.") } I then source("First.R"), ok. and quit R. WhenI restart, nothing happens - maybe because I didn't save the image? But I don't want to have to save the image, I want to make a dynamic startup of R with a file loaded, and execute a function call. I alse tried this approach: $ R < file.r it seems to load, almost, then R quits. Any ideas? Thanks for your help in any case! GF. On 10/24/06, Leeds, Mark (IED) <Mark.Leeds@morganstanley.com> wrote:> > You can have a .First function in the directory you are working in ( put > The function in a file called First.R for ease of remembering ) or a > .Profile file in your > Home directory. I couldn't tell if you were on windows or linux. > > In either case, have the line source("Rprogram.R") in either of the > above and that source will be loaded when > You start R. If you do it using First.R, you have to source("First.R") > once in the > Directory you are working in in order for it to know for the next time > and any time after that. > > > > -----Original Message----- > From: r-help-bounces@stat.math.ethz.ch > [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Grateful Frog > Sent: Tuesday, October 24, 2006 1:17 PM > To: r-help@stat.math.ethz.ch > Subject: [R] How to start R with a file loaded? > > Hi! > > I've made great progress in my R programming, but I am again stuck on a > beginner's problem. > > I would like to start R with a command line that loads a file, and if > possible, executes a function. > > Can anyone give me an example of how to do this? > > For example, in lisp, I would say: > > $ lisp -load toto.lisp -eval '(do-something $PORT)' > > to load the file "toto.lisp", then evaluate the expression with the > shell envt variable bound properly. > > I'd like to do this in R, but can't figure it out! > > Thanks, > GF. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -------------------------------------------------------- > > This is not an offer (or solicitation of an offer) to buy/sell the > securities/instruments mentioned or an official confirmation. Morgan > Stanley may deal as principal in or own or act as market maker for > securities/instruments mentioned or may advise the issuers. This is not > research and is not from MS Research but it may refer to a research > analyst/research report. Unless indicated, these views are the author's and > may differ from those of Morgan Stanley research or others in the Firm. We > do not represent this is accurate or complete and we may not update > this. Past performance is not indicative of future returns. For additional > information, research reports and important disclosures, contact me or see > https://secure.ms.com/servlet/cls. You should not use e-mail to request, > authorize or effect the purchase or sale of any security or instrument, to > send transfer instructions, or to effect any other transactions. We cannot > guarantee that any such requests received via e-mail will be processed in a > timely manner. This communication is solely for the addressee(s) and may > contain confidential information. We do not waive confidentiality by > mistransmission. Contact me if you do not wish to receive these > communications. In the UK, this communication is directed in the UK to > those persons who are market counterparties or intermediate customers (as > defined in the UK Financial Services Authority's rules). >[[alternative HTML version deleted]]
Thanks! It works! I'm so sorry for my ignorance of R. I took no offense, of course not! You're trying to help me! I can only thank you! So, it's midnight my time, and I succeeded, although I was about to give up and go to bed in despair, now I can sleep peacefully thinking of my R program running all by itself! Thanks for your help! If you ever need any help with lisp or python, maybe I can repay the service! Cheers, GF. http://gratefulfrog.net On 10/24/06, Leeds, Mark (IED) <Mark.Leeds@morganstanley.com> wrote:> > hi : i may not have been so clear before and it's hard to explain in > email so i will write it in steps. don't > take offense. i just know how making one little error can make things seem > impossible when they actually aren;t. > > 1) take the line source("First.R") out of your function below. that's one > problem. > > 2) then, name the file that contains the function below "First.R". ( > obviously without quotes ). > > 3) Make sure this file First.R is in the directory you want to > automatically start client.r in. > > 4) Then, go to this directory and type R. > > 5) then, right at the prompt type "source("First.R"). Nothing should > happen. > > 6) then, type q() and when it asks you to save workpace,answer yes. > > 7) then, go back in to R, exactly the same way you did before and this > time without you doing anything , it should say "it worked" and you will > have client.r loaded. > > generally, i think it's better to name things .R or .q rather than .r but > it probably doesn't matter. > > > > > ------------------------------ > *From:* Grateful Frog [mailto:gratefulfrog@gmail.com] > *Sent:* Tuesday, October 24, 2006 3:46 PM > *To:* Leeds, Mark (IED); r-help@stat.math.ethz.ch > *Subject:* Re: [R] How to start R with a file loaded? > > Hi! > > Thanks for your reply. > > Indeed, I'm on Linux. > > I tried to do what you said, but nothing happened. > > I made a file called First.R in my work directory. It contains this code > > .First<-function(){ > source("First.R") > source("client.r") > cat("it worked.") > } > > I then source("First.R"), ok. and quit R. > WhenI restart, nothing happens - maybe because I didn't save the image? > > But I don't want to have to save the image, I want to make a dynamic > startup of R with a file loaded, and execute a function call. > > I alse tried this approach: > > $ R < file.r > > it seems to load, almost, then R quits. > > Any ideas? > > Thanks for your help in any case! > GF. > > On 10/24/06, Leeds, Mark (IED) <Mark.Leeds@morganstanley.com > wrote: > > > > You can have a .First function in the directory you are working in ( put > > > > The function in a file called First.R for ease of remembering ) or a > > .Profile file in your > > Home directory. I couldn't tell if you were on windows or linux. > > > > In either case, have the line source("Rprogram.R ") in either of the > > above and that source will be loaded when > > You start R. If you do it using First.R, you have to source("First.R") > > once in the > > Directory you are working in in order for it to know for the next time > > and any time after that. > > > > > > > > -----Original Message----- > > From: r-help-bounces@stat.math.ethz.ch > > [mailto: r-help-bounces@stat.math.ethz.ch] On Behalf Of Grateful Frog > > Sent: Tuesday, October 24, 2006 1:17 PM > > To: r-help@stat.math.ethz.ch > > Subject: [R] How to start R with a file loaded? > > > > Hi! > > > > I've made great progress in my R programming, but I am again stuck on a > > beginner's problem. > > > > I would like to start R with a command line that loads a file, and if > > possible, executes a function. > > > > Can anyone give me an example of how to do this? > > > > For example, in lisp, I would say: > > > > $ lisp -load toto.lisp -eval '(do-something $PORT)' > > > > to load the file "toto.lisp", then evaluate the expression with the > > shell envt variable bound properly. > > > > I'd like to do this in R, but can't figure it out! > > > > Thanks, > > GF. > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > -------------------------------------------------------- > > > > This is not an offer (or solicitation of an offer) to buy/sell the > > securities/instruments mentioned or an official confirmation. Morgan > > Stanley may deal as principal in or own or act as market maker for > > securities/instruments mentioned or may advise the issuers. This is not > > research and is not from MS Research but it may refer to a research > > analyst/research report. Unless indicated, these views are the author's and > > may differ from those of Morgan Stanley research or others in the Firm. We > > do not represent this is accurate or complete and we may not update > > this. Past performance is not indicative of future returns. For additional > > information, research reports and important disclosures, contact me or see > > https://secure.ms.com/servlet/cls. You should not use e-mail to > > request, authorize or effect the purchase or sale of any security or > > instrument, to send transfer instructions, or to effect any other > > transactions. We cannot guarantee that any such requests received via > > e-mail will be processed in a timely manner. This communication is solely > > for the addressee(s) and may contain confidential information. We do not > > waive confidentiality by mistransmission. Contact me if you do not wish to > > receive these communications. In the UK, this communication is directed in > > the UK to those persons who are market counterparties or intermediate > > customers (as defined in the UK Financial Services Authority's rules). > > > > ------------------------------ > This is not an offer (or solicitation of an offer) to buy/sell the > securities/instruments mentioned or an official confirmation. Morgan > Stanley may deal as principal in or own or act as market maker for > securities/instruments mentioned or may advise the issuers. This is not > research and is not from MS Research but it may refer to a research > analyst/research report. Unless indicated, these views are the author's and > may differ from those of Morgan Stanley research or others in the Firm. We > do not represent this is accurate or complete and we may not update this. > Past performance is not indicative of future returns. For additional > information, research reports and important disclosures, contact me or see > https://secure.ms.com/servlet/cls. You should not use e-mail to request, > authorize or effect the purchase or sale of any security or instrument, to > send transfer instructions, or to effect any other transactions. We cannot > guarantee that any such requests received via e-mail will be processed in a > timely manner. This communication is solely for the addressee(s) and may > contain confidential information. We do not waive confidentiality by > mistransmission. Contact me if you do not wish to receive these > communications. In the UK, this communication is directed in the UK to > those persons who are market counterparties or intermediate customers (as > defined in the UK Financial Services Authority's rules). >[[alternative HTML version deleted]]
Assume you want to execute code in 'mycode.R', the easiest way is: echo "source('mycode.R')" | R --vanilla --quiet If you do it in a shell script, you can also pass variables to your code like this (list of shell script): #!/bin/sh echo "var1=${1};var2=${2};source('mycode.R')" | R --vanilla -- quiet Good luck, Oleg On 24/10/06, Grateful Frog <gratefulfrog@gmail.com> wrote:> > Hi! > > I've made great progress in my R programming, but I am again stuck on a > beginner's problem. > > I would like to start R with a command line that loads a file, and if > possible, executes a function. > > Can anyone give me an example of how to do this? > > For example, in lisp, I would say: > > $ lisp -load toto.lisp -eval '(do-something $PORT)' > > to load the file "toto.lisp", then evaluate the expression with the shell > envt variable bound properly. > > I'd like to do this in R, but can't figure it out! > > Thanks, > GF. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Thanks to all you numerous r-helpers, the problem is solved! It's so much easier when someone explains. I was going crazy trying to understand the manual on my own! Thanks again to everyone! GF On 10/25/06, Pierce, Ken <ken.pierce@oregonstate.edu> wrote:> > You can edit the below file which runs during R startup. This is where > you might put a .First file. > I have a bunch of functions I've written so I have a line in this file > that sources my functions file. > You can also put library commands here to autoload stuff you always > want. > > > C:\Program Files\R\R-2.3.1\etc\Rprofile.site > > ##############Example below > > # Things you might want to change > > # options(papersize="a4") > # options(editor="notepad") > # options(pager="internal") > > # to prefer Compiled HTML help > # options(chmhelp=TRUE) > > # to prefer HTML help > # options(htmlhelp=TRUE) > > options(IDE = 'C:/Program files/Tinn-R/bin/Tinn-R.exe') > options(use.DDE = TRUE) > > library(svIDE) > library(svSocket) > library(svIO) > guiDDEInstall() > > source("C:\\Rprojects\\functions\\Rfunctions.r") > > > .First <- function(){ > cat("\n Rrrr! The Pirates statistics program!\n\n") > > } > > > > > -----Original Message----- > From: r-help-bounces@stat.math.ethz.ch > [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Grateful Frog > Sent: Tuesday, October 24, 2006 10:17 AM > To: r-help@stat.math.ethz.ch > Subject: [R] How to start R with a file loaded? > > Hi! > > I've made great progress in my R programming, but I am again stuck on a > beginner's problem. > > I would like to start R with a command line that loads a file, and if > possible, executes a function. > > Can anyone give me an example of how to do this? > > For example, in lisp, I would say: > > $ lisp -load toto.lisp -eval '(do-something $PORT)' > > to load the file "toto.lisp", then evaluate the expression with the > shell envt variable bound properly. > > I'd like to do this in R, but can't figure it out! > > Thanks, > GF. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]