[R] Can I read a file into my workspace from Rprofile.site?
Duncan Murdoch
murdoch at stats.uwo.ca
Tue Mar 31 01:41:37 CEST 2009
Elaine Jones wrote:
> I am running R version 2.8.1 on Windows XP OS.
>
> When I launch R, I would like to automatically read a file containing my
> database connections, user ids, and passwords into my workspace.
>
> I tried including this in my Rprofile.site file:
>
> ...
> local({
> old <- getOption("defaultPackages")
> options(defaultPackages = c(old, "Rcmdr","RODBC", "utils"))
> })
>
> .First <- function() {
> library(utils)
> setwd("C:/Documents and Settings/Administrator/My Documents/R")
> connections <- read.csv("connections.csv", header=TRUE)
> cat("\n Welcome to R Elaine!\n\n")
> }
>
>
The connections variable will be local to .First, and will disappear
after that function is done. To save the variable into the global
environment, use
connections <<- read.csv("connections.csv", header=TRUE)
instead.
Duncan Murdoch
> ...
>
> When I launch R, it does not give me any error. The working directory
> appears to be set by the Rprofile.site file, but the connections object is
> not in my workspace:
>
>
> Welcome to R Elaine!
>
> Loading required package: tcltk
> Loading Tcl/Tk interface ... done
> Loading required package: car
>
> Rcmdr Version 1.4-7
>
>
>> ls()
>>
> character(0)
>
>
> Any suggestions for how to resolve are appreciated!
>
> **************** Elaine McGovern Jones ************************
>
> ISC Tape and DASD Storage Products
> Characterization and Failure Analysis Engineering
> Phone: 408 284 4853 Internal: 3-4853
> jones2 at us.ibm.com
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>
More information about the R-help
mailing list