[R] Rprofile file to automatically plot data, tried using the .First command.

Liaw, Andy andy_liaw at merck.com
Thu Jan 6 02:58:29 CET 2005


No.  You put the _whole_ thing into .First(), not just the plot statement.
One possibility is to have the code in a script file (say myscript.R) and
define .First as follows:

.First <- function() source("myscript.R")

Haven't try it myself, though.

Andy

> From: John Fisler
> 
> Dear Dr. Andreas Kiermeier and the R help Community,
> 
> Thank you for your idea on putting the plot command in a 
> .First statement.
> 
> I tried putting the plot comamnd in a '.First' statement like 
> the following:
> 
> x <- c(1,2,3,4,5)
> y <- c(2,5,6,3,10)
> 
> .First <- function() {
> 
> plot(x,y)
> 
> }
> 
> and had the same error message:
> 
> Error in .First() : couldn't find function "plot"
> 
> Should I be put the plot command in a different 'startup' file?
> 
> Thanks,
> 
> John
> 
> the following commands
> 
> Kiermeier, Andreas (PIRSA - SARDI) wrote:
> > Dear John,
> > 
> > I belive your problem has to do with the sequence of 
> startup. I think that
> > .Rprofile is called before the required libraries are attached.
> > 
> > You might like to try putting your code into a .First() 
> function and run it
> > that way.
> > 
> > Cheers,
> > 
> > Andreas
> > 
> > Dr Andreas Kiermeier
> > Statistician
> > SARDI FOOD SAFETY PROGRAM
> > 
> > 33 Flemington Street
> > Glenside   SA   5065
> > Phone:  +61 8 8207 7884
> > Fax:       +61 8 8207 7854
> > Mobile: 0423 028 565
> > 
> > Email: Kiermeier.Andreas at saugov.sa.gov.au
> > _____________________________
> > 
> > The information in this e-mail and attachments (if any) may 
> be confidential
> > and/or legally privileged. If you are not the intended 
> recipient, any
> > disclosure, copying, distribution or action taken is 
> prohibited. SARDI, The
> > South Australian Research and Development Institute, is the research
> > division of Primary Industries and Resources (SA) 
> > 
> > 
> > 
> > -----Original Message-----
> > From: r-help-bounces at stat.math.ethz.ch
> > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of John Fisler
> > Sent: Thursday, 6 January 2005 09:21
> > To: r-help at lists.R-project.org; John Fisler
> > Subject: [R] Using the Rprofile file to automatically plot data on
> > Startup of R version 2.0.1.
> > 
> > 
> > Dear R Help Members,
> > 
> > I have some R functions that plot semiconductor data.  I 
> would like to 
> > automate these plots for individuals in our group such that 
> they don't 
> > have to know R.  I have read the R help manuals and 
> postings but have 
> > not found this problem.
> > 
> > I am using R version 2.0.1 under a Windows 2000 operating system.
> > 
> > The following is a simplified version of what I am tring to do:
> > 
> > If I insert the following R code in the Rprofile file located in 
> > directory 'C:\Program Files\R\rw2001\etc':
> > 
> > x <- c(1,2,3,4,5)
> > y <- c(2,5,6,3,10)
> > plot(x,y)
> > 
> > Using the Rgui.exe or the R.exe terminal version of R the following 
> > message appears:
> > 
> > Error: couldn't find function "plot"
> > 
> > If I copy and paste the command 'plot(x,y)' into the R 
> Console Window 
> > the scatter plot appears in the R Graphics Device window as 
> expected.
> > 
> > I have also tried putting the above code in a 'R' script 
> file and using 
> > the source command but I get the same error message.
> > 
> > Any help would be appreciated.
> > 
> > Thank you.
> > 
> > John Fisler
> > 
> > ______________________________________________
> > R-help at 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
> 
> ______________________________________________
> R-help at 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
> 
>




More information about the R-help mailing list