Francisco J Molina
2004-Jul-21 21:30 UTC
[R] add more data to a data file, problem with .Rprofile
Hi, Is there a way to incorporate an R object x to a file already containing R objects? It seems that 'save' is not capable to do this. If I save x to a file containing previously saved data, then I will lose this data. I use the funcion hsv in .Rprofile but it is recognized. Couriously, if I source .Rprofile when R is already running I do not get any error message. Thank you.
> From: Francisco J Molina > > Hi, > > Is there a way to incorporate an R object x to a file already > containing R objects? > It seems that 'save' is not capable to do this. If I save x > to a file containing > previously saved data, then I will lose this data.See if the following helps:> x <- 2 > save(x, file="x.rda") > rm(x) > attach("x.rda") > assign("y", 3, pos=2) > ls(2)[1] "x" "y"> save(list=ls(2), file="x.rda") > detach(2) > xError: Object "x" not found> yError: Object "y" not found> attach("x.rda") > x[1] 2> y[1] 3> ls(2)[1] "x" "y"> I use the funcion hsv in .Rprofile but it is recognized. > Couriously, if I source .Rprofile > when R is already running I do not get any error message.Not sure what you mean... Andy> Thank you. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
Roger D. Peng
2004-Jul-22 12:35 UTC
[R] add more data to a data file, problem with .Rprofile
You should take a look at ?setHook if you use hsv() in .Rprofile.
That way when the `graphics' package is loaded, it will automatically
run whatever hook function you specified involving hsv(). For
example, you might include something like
setHook(packageEvent("graphics", "onLoad"),
function(...) {
hsv <- graphics::hsv
## Do whatever you need to do with hsv()
})
-roger
Francisco J Molina wrote:> Hi,
>
> Is there a way to incorporate an R object x to a file already
> containing R objects? It seems that 'save' is not capable to do
> this. If I save x to a file containing previously saved data, then
> I will lose this data.
>
> I use the funcion hsv in .Rprofile but it is recognized.
> Couriously, if I source .Rprofile when R is already running I do
> not get any error message.
>
> Thank you.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do
> read the posting guide! http://www.R-project.org/posting-guide.html
>
>