Re: [R] loading edited functions already in saved workspace automatically

2017-05-09 Thread Ralf Goertz
Am Tue, 09 May 2017 10:00:17 -0700
schrieb Jeff Newmiller :

> This boils down to the fact that some "my ways" are more effective in
> the long run than others.. but I really want to address the complaint
> 
> "... sometimes tedious to rebuild my environment by reexecuting
> commands in the history"
> 
> by asserting that letting R re-run a script that loads my functions
> and packages (though perhaps not the data analysis steps) is always
> very fast and convenient to do explicitly. I almost never use the
> history file feature, because I type nearly every R instruction I use
> into a script file and execute/edit it until it does what I want. I
> keep functions in a separate file or package, and steps dealing with
> a particular data set in their own file that uses source() to load
> the functions) even when I am executing the lines interactively. My
> goal is to regularly re-execute the whole script so that
> tomorrow/next year/whenever someone notices something was wrong then
> I can re-execute the sequence without following the dead ends I went
> down the first time (as using a history file does) and I don't have a
> separate clean-up-the-history-file step to go through to create it.
> When I have confirmed that the script still works as it did before
> then I can find where the analysis/data problem went wrong and fix it. 

My usual work with R is probably a bit different from yours. As I said
before I work on many projects (often simultaneously) but I do routine
work. For that I have my super function, the one I want to reload every
time R starts, at the moment about 250 lines of code. This is always
work in progress. In almost every project there is something that makes
me edit this function. But in order to apply my function I need to
prepare the data, e.g. getting them from a database or csv files,
renaming the columns of data.frames etc. This is all tedious and not
worth putting in scripts because these steps are very specific to the
project and are rarely needed more than once. Sometimes one or two data
records in project on which I worked a few days before turn out to be
wrong and need to be changed. That's why I want to keep the data because
changing the data.frame directly is much easier then starting from
scratch. Meanwhile my function has evolved. But in the .RData file is
still the old version, which is bad.

However, I found a solution! .Last() gets executed before saving here,
too. I simply had forgotten that I need to use rm() with pos=1, i.e.
rm(myfun,pos=1) because otherwise rm wants to delete myfun from within
the context of the function .Last() where it doesn't live. I changed my
.Rprofile to:

.First=function(){
assign("myfun",eval(parse(file=("~/R/myfun.R"))),pos=1)
}
.Last=function(){
rm(.First,pos=1)
rm(myfun,pos=1)
rm(.Last,pos=1)
}

and everything works as I want it. So no design flaw but still way too
complicated in my opinion. Thanks to everybody who came up with
suggestions.

Ralf

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] loading edited functions already in saved workspace automatically

2017-05-09 Thread Jeff Newmiller
This boils down to the fact that some "my ways" are more effective in the long 
run than others.. but I really want to address the complaint

"... sometimes tedious to rebuild my environment by reexecuting commands in the 
history"

by asserting that letting R re-run a script that loads my functions and 
packages (though perhaps not the data analysis steps) is always very fast and 
convenient to do explicitly. I almost never use the history file feature, 
because I type nearly every R instruction I use into a script file and 
execute/edit it until it does what I want. I keep functions in a separate file 
or package, and steps dealing with a particular data set in their own file that 
uses source() to load the functions) even when I am executing the lines 
interactively. My goal is to regularly re-execute the whole script so that 
tomorrow/next year/whenever someone notices something was wrong then I can 
re-execute the sequence without following the dead ends I went down the first 
time (as using a history file does) and I don't have a separate 
clean-up-the-history-file step to go through to create it. When I have 
confirmed that the script still works as it did before then I can find where 
the analysis/data problem went wrong and fix it. 

This does not mean I never use RData files to reduce how often I re-do slow 
calculations... but it does mean that I always have my script that loads the 
necessary packages and functions rather than using versions of functions in the 
RData file. It is useful to avoid becoming dependent on saved intermediate 
saved data files so you don't continue to encounter the effects of script 
errors that you have already fixed earlier in the analysis. 

It becomes more convenient to minimize dependency on automatic startup behavior 
when you want to share your script with someone else or run it yourself on a 
different computer (say, a powerful server). If you have the script habit then 
these hiccups with moving around are non-issues, and you can perform more and 
more complex analyses over time because you don't have to remember all the 
individual steps nor do you have to sort through the dead ends in your history 
file over and over. 

The editor you use can make a huge difference in making this work... get one 
that has a hot key that lets you execute one line at a time straight from the 
editor rather than requiring an explicit copy/paste. RStudio, Notepad++/NppToR, 
IntelliJ IDEA, vim-r, and ESS are a few options I am aware of. RStudio also 
supports full screen debugging of R so you can more easily reproduce the exact 
conditions where things go wrong inside functions as well. 

-- 
Sent from my phone. Please excuse my brevity.

On May 9, 2017 8:49:22 AM PDT, Michael Friendly  wrote:
>Ralf:
>
>You are afflicted with several mind bugs:
>* the "my-way mind bug" -- "I want to do it MY WAY, because that's sort
>
>of what
>I know" and also,
>* the "my-square-peg-should-fit-into-this-round-hole mind bug" -- "R 
>should be able to
>do it MY WAY, but it puts obstacles in my path," perhaps a subsidiary, 
>but more technical:
>* the "loading-a-function-or-data-is-the-same mind bug"
>As in many things R, you can't always get to MY WAY from there, at
>least 
>not without a tortuous journey.
>
>You think you should be able to do everything you want in .Rprofile,
>but 
>then you posed two separate problems:
>(a) save/reload history
>(b) save/reload functions and data
>
>If you recognize them as two separate problems, there is an easier
>path:
>(a) use .Rprofile only for making your history persistent, as I
>described
>(b) Put your functions & data you always want available in a package; 
>you can load it from .Rprofile
>
>I originally defined a bunch of handy functions (e.g., cd(), a setwd() 
>replacement, that works more like `cd` on unix, in that `cd()` returns 
>to the previous directory; it also changes the Windows title to
>`RGui:`  abbreviation of getwd() )
>
>I moved them all out of .Rprofile, made a package `myutil` and now load
>
>them from there with
>
>  #==
>  # load default packages
>  #==
>  if (!require(myutil)) warning("myutil functions not available")
>
>hope this helps,
>-Michael
>
>On 5/9/2017 10:20 AM, Ralf Goertz wrote:
>> Am Sat, 6 May 2017 11:17:42 -0400
>> schrieb Michael Friendly :
>>
>>> On 5/5/2017 10:23 AM, Ralf Goertz wrote:
 Am Fri, 05 May 2017 07:14:36 -0700
 schrieb Jeff Newmiller :
   
> R normally prompts you to save .RData, but it just automatically
> saves .Rhistory... the two are unrelated.
 Not here. If I say "n" to the prompted question "Save workspace
 image? [y/n/c]: " my history doesn't get saved.

 Version:

 R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
 Copyright (C) 2016 The R Foundation for Statistical Computing
 Platform: x86_64-suse-linux-gnu (64-bit)
   
>>> On 

Re: [R] loading edited functions already in saved workspace automatically

2017-05-09 Thread Michael Friendly

Ralf:

You are afflicted with several mind bugs:
* the "my-way mind bug" -- "I want to do it MY WAY, because that's sort 
of what

I know" and also,
* the "my-square-peg-should-fit-into-this-round-hole mind bug" -- "R 
should be able to
do it MY WAY, but it puts obstacles in my path," perhaps a subsidiary, 
but more technical:

* the "loading-a-function-or-data-is-the-same mind bug"
As in many things R, you can't always get to MY WAY from there, at least 
not without a tortuous journey.


You think you should be able to do everything you want in .Rprofile, but 
then you posed two separate problems:

(a) save/reload history
(b) save/reload functions and data

If you recognize them as two separate problems, there is an easier path:
(a) use .Rprofile only for making your history persistent, as I described
(b) Put your functions & data you always want available in a package; 
you can load it from .Rprofile


I originally defined a bunch of handy functions (e.g., cd(), a setwd() 
replacement, that works more like `cd` on unix, in that `cd()` returns 
to the previous directory; it also changes the Windows title to

`RGui:`  abbreviation of getwd() )

I moved them all out of .Rprofile, made a package `myutil` and now load 
them from there with


 #==
 # load default packages
 #==
 if (!require(myutil)) warning("myutil functions not available")

hope this helps,
-Michael

On 5/9/2017 10:20 AM, Ralf Goertz wrote:

Am Sat, 6 May 2017 11:17:42 -0400
schrieb Michael Friendly :


On 5/5/2017 10:23 AM, Ralf Goertz wrote:

Am Fri, 05 May 2017 07:14:36 -0700
schrieb Jeff Newmiller :
  

R normally prompts you to save .RData, but it just automatically
saves .Rhistory... the two are unrelated.

Not here. If I say "n" to the prompted question "Save workspace
image? [y/n/c]: " my history doesn't get saved.

Version:

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-suse-linux-gnu (64-bit)
  

On Windoze, here's what I use in my .Rprofile, which runs every time
I start an RGUI coonsole.  The key is .First & .Last to load/save
history automagically.

Hi Michael,

thanks. This helps with saving the history without saving the data. But
actually I'd really like to save both and still be able to load
functions automatically from .Rprofile. Not saving the data as Jeff
suggested is not a good option because it is sometimes tedious to
rebuild my environment by reexecuting commands in the history. And I
explained in my OP why I can't use .First() to achieve my goal.

But let me try again to explain the problem because I think not
everybody understood what I was trying to say. For simplicity I use the
plain variable "a" instead of a function. Start a fresh session and
remove all variables, define one variable and quit with saving:


rm(list=ls())
a=17
quit(save="yes")

Now, before opening a new session edit .Rprofile such that it contains
just the two lines:

print("Hello from .Rprofile")
a=42

Start a new session where your saved environment will be loaded.
Observe that you see the line

[1] "Hello from .Rprofile"

proving that the commands in .Rprofile have been executed. Now look at
"a":


a

[1] 17


You would expect to see this because *after* your "Hello" line you find

[Previously saved workspace restored]

So you have set "a" to 42 in .Rprofile but it gets overwritten from the
previously saved and now restored workspace. On the other hand, .First()
gets executed after the restoring of the workspace. Therefore, I could
edit .Rprofile to read

.First=function(){ assign("a",42,pos=1) }

Now, after starting I see that "a" is indeed 42. But then it turns out
that from now on I need "a" to be 11. After editing .Rprofile
accordingly, I am quite hopeful but after starting a new session I see
that "a" is still 42. Why is that? Because .First() was saved and when I
started a new session it got a new function body (setting "a" to 11) but
before it could be executed it was again overwritten by the old value
(setting "a" to 42) and I am chasing my own tail. Sigh.

.Last() doesn't help. Apparently (at least on my linux system) it is
executed *after* saving the environment so too late to remove anything
you don't want saved. In that regard linux doesn't seem to be typical,
since in "?.Last" the reverse order is described as typical:

  Exactly what happens at termination of an R session depends on the
  platform and GUI interface in use.  A typical sequence is to run
  ‘.Last()’ and ‘.Last.sys()’ (unless ‘runLast’ is false), to save
  the workspace if requested (and in most cases also to save the
  session history: see ‘savehistory’), then run any finalizers (see
  ‘reg.finalizer’) that have been set to be run on exit, close all
  open graphics devices, remove the session temporary directory and
  print any remaining warnings (e.g., from 

Re: [R] loading edited functions already in saved workspace automatically

2017-05-09 Thread Ralf Goertz
Am Sat, 6 May 2017 11:17:42 -0400
schrieb Michael Friendly :

> On 5/5/2017 10:23 AM, Ralf Goertz wrote:
> > Am Fri, 05 May 2017 07:14:36 -0700
> > schrieb Jeff Newmiller :
> >  
> >> R normally prompts you to save .RData, but it just automatically
> >> saves .Rhistory... the two are unrelated.  
> >
> > Not here. If I say "n" to the prompted question "Save workspace
> > image? [y/n/c]: " my history doesn't get saved.
> >
> > Version:
> >
> > R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
> > Copyright (C) 2016 The R Foundation for Statistical Computing
> > Platform: x86_64-suse-linux-gnu (64-bit)
> >  
> 
> On Windoze, here's what I use in my .Rprofile, which runs every time
> I start an RGUI coonsole.  The key is .First & .Last to load/save
> history automagically.

Hi Michael,

thanks. This helps with saving the history without saving the data. But
actually I'd really like to save both and still be able to load
functions automatically from .Rprofile. Not saving the data as Jeff
suggested is not a good option because it is sometimes tedious to
rebuild my environment by reexecuting commands in the history. And I
explained in my OP why I can't use .First() to achieve my goal.

But let me try again to explain the problem because I think not
everybody understood what I was trying to say. For simplicity I use the
plain variable "a" instead of a function. Start a fresh session and
remove all variables, define one variable and quit with saving:

> rm(list=ls())
> a=17
> quit(save="yes")

Now, before opening a new session edit .Rprofile such that it contains
just the two lines:

print("Hello from .Rprofile")
a=42

Start a new session where your saved environment will be loaded.
Observe that you see the line 

[1] "Hello from .Rprofile"

proving that the commands in .Rprofile have been executed. Now look at
"a":

> a
[1] 17


You would expect to see this because *after* your "Hello" line you find

[Previously saved workspace restored]

So you have set "a" to 42 in .Rprofile but it gets overwritten from the
previously saved and now restored workspace. On the other hand, .First()
gets executed after the restoring of the workspace. Therefore, I could
edit .Rprofile to read

.First=function(){ assign("a",42,pos=1) }

Now, after starting I see that "a" is indeed 42. But then it turns out
that from now on I need "a" to be 11. After editing .Rprofile
accordingly, I am quite hopeful but after starting a new session I see
that "a" is still 42. Why is that? Because .First() was saved and when I
started a new session it got a new function body (setting "a" to 11) but
before it could be executed it was again overwritten by the old value
(setting "a" to 42) and I am chasing my own tail. Sigh.

.Last() doesn't help. Apparently (at least on my linux system) it is
executed *after* saving the environment so too late to remove anything
you don't want saved. In that regard linux doesn't seem to be typical,
since in "?.Last" the reverse order is described as typical:

 Exactly what happens at termination of an R session depends on the
 platform and GUI interface in use.  A typical sequence is to run
 ‘.Last()’ and ‘.Last.sys()’ (unless ‘runLast’ is false), to save
 the workspace if requested (and in most cases also to save the
 session history: see ‘savehistory’), then run any finalizers (see
 ‘reg.finalizer’) that have been set to be run on exit, close all
 open graphics devices, remove the session temporary directory and
 print any remaining warnings (e.g., from ‘.Last()’ and device
 closure).


IMHO this is a design flaw.

Ralf

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] loading edited functions already in saved workspace automatically

2017-05-06 Thread Michael Friendly


On 5/5/2017 10:23 AM, Ralf Goertz wrote:

Am Fri, 05 May 2017 07:14:36 -0700
schrieb Jeff Newmiller :


R normally prompts you to save .RData, but it just automatically
saves .Rhistory... the two are unrelated.


Not here. If I say "n" to the prompted question "Save workspace image?
[y/n/c]: " my history doesn't get saved.

Version:

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-suse-linux-gnu (64-bit)



On Windoze, here's what I use in my .Rprofile, which runs every time I 
start an RGUI coonsole.  The key is .First & .Last to load/save

history automagically.  There is some extra overhead in my use of
old.packages() here, but that is for a different reason.



### History

# could use Sys.getenv("R_HISTFILE")
# Sys.getenv("R_HISTSIZE"=1024)
.First <- function() {
if(interactive()) {
if (.Platform$GUI == "Rgui") {
			histfile <- if (file.exists(".Rhistory")) ".Rhistory" else 
"c:/R/.Rhistory"

try(utils::loadhistory(histfile))
old <- utils::old.packages()
	if (! is.null(old)) cat("Updatable packages: ", old[,1], "\n", 
fill=TRUE) else cat("All packages up to date\n")

}
  setwd("c:/R")
  cat(paste("[.Rprofile loaded, current dir:", getwd(), 
"]\n"),sep=" ")	

  }
}


.Last <- function()
if(interactive() && .Platform$GUI == "Rgui") {
		 histfile <- if (file.exists(".Rhistory")) ".Rhistory" else 
"c:/R/.Rhistory"

 try(utils::savehistory(histfile))
}


--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] loading edited functions already in saved workspace automatically

2017-05-05 Thread Bert Gunter
Haven't followed this closely, but
?Startup
and links therein might be useful (esp .First).

Bert


On May 5, 2017 11:47 AM, "David Winsemius"  wrote:


> On May 5, 2017, at 7:48 AM, Michael Dewey  wrote:
>
> Dear Ralf
>
> You can manually save it with
> savehistory(insertyour preferred filenamehere.r)
>
> or does that not do what you hoped?

Or you can exit to your system browser and copy of the desired sections of
the .Rhistory file that you desire archiving to a text editor (after you
find the ofttimes hidden file.) It's just a text file.

The details vary across OSes. I don't think you told us yours. Might help
to read the Posting Guide.

--
David


>
> On 05/05/2017 14:44, Ralf Goertz wrote:
>> Am Fri, 05 May 2017 06:30:01 -0700
>> schrieb Jeff Newmiller :
>>
>>> The answer most people seem to use is to avoid depending on functions
>>> in RData files, and in particular avoiding ever saving the
>>> "automatic" ".RData" files at all. (Some people avoid using any RData
>>> files, but the automatic loading of functions by ".RData" files is a
>>> particularly pernicious source of evil as you have already
>>> discovered.)
>>>
>>> That is,  always work toward building scripts that you run to restore
>>> your workspace rather than depending on save files. Don't depend on
>>> save files to keep track of what you do interactively. This also
>>> usually means that there should be little if anything in
>>> your .Rprofile because that tends to build non-reproducibility into
>>> your scripts.
>>
>> Hi Jeff,
>>
>> thanks for your answer. Actually, I don't use the workspace saving
>> feature primarily for the data but for the command line history. Is
>> there a way to just save .Rhistory?
>>
>> Ralf
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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 email has been checked for viruses by AVG.
>> http://www.avg.com
>>
>>
>
> --
> Michael
> http://www.dewey.myzen.co.uk/home.html
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] loading edited functions already in saved workspace automatically

2017-05-05 Thread David Winsemius

> On May 5, 2017, at 7:48 AM, Michael Dewey  wrote:
> 
> Dear Ralf
> 
> You can manually save it with
> savehistory(insertyour preferred filenamehere.r)
> 
> or does that not do what you hoped?

Or you can exit to your system browser and copy of the desired sections of the 
.Rhistory file that you desire archiving to a text editor (after you find the 
ofttimes hidden file.) It's just a text file. 

The details vary across OSes. I don't think you told us yours. Might help to 
read the Posting Guide.

-- 
David


> 
> On 05/05/2017 14:44, Ralf Goertz wrote:
>> Am Fri, 05 May 2017 06:30:01 -0700
>> schrieb Jeff Newmiller :
>> 
>>> The answer most people seem to use is to avoid depending on functions
>>> in RData files, and in particular avoiding ever saving the
>>> "automatic" ".RData" files at all. (Some people avoid using any RData
>>> files, but the automatic loading of functions by ".RData" files is a
>>> particularly pernicious source of evil as you have already
>>> discovered.)
>>> 
>>> That is,  always work toward building scripts that you run to restore
>>> your workspace rather than depending on save files. Don't depend on
>>> save files to keep track of what you do interactively. This also
>>> usually means that there should be little if anything in
>>> your .Rprofile because that tends to build non-reproducibility into
>>> your scripts.
>> 
>> Hi Jeff,
>> 
>> thanks for your answer. Actually, I don't use the workspace saving
>> feature primarily for the data but for the command line history. Is
>> there a way to just save .Rhistory?
>> 
>> Ralf
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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 email has been checked for viruses by AVG.
>> http://www.avg.com
>> 
>> 
> 
> -- 
> Michael
> http://www.dewey.myzen.co.uk/home.html
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] loading edited functions already in saved workspace automatically

2017-05-05 Thread Michael Dewey

Dear Ralf

You can manually save it with
savehistory(insertyour preferred filenamehere.r)

or does that not do what you hoped?

On 05/05/2017 14:44, Ralf Goertz wrote:

Am Fri, 05 May 2017 06:30:01 -0700
schrieb Jeff Newmiller :


The answer most people seem to use is to avoid depending on functions
in RData files, and in particular avoiding ever saving the
"automatic" ".RData" files at all. (Some people avoid using any RData
files, but the automatic loading of functions by ".RData" files is a
particularly pernicious source of evil as you have already
discovered.)

That is,  always work toward building scripts that you run to restore
your workspace rather than depending on save files. Don't depend on
save files to keep track of what you do interactively. This also
usually means that there should be little if anything in
your .Rprofile because that tends to build non-reproducibility into
your scripts.


Hi Jeff,

thanks for your answer. Actually, I don't use the workspace saving
feature primarily for the data but for the command line history. Is
there a way to just save .Rhistory?

Ralf

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 email has been checked for viruses by AVG.
http://www.avg.com




--
Michael
http://www.dewey.myzen.co.uk/home.html

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] loading edited functions already in saved workspace automatically

2017-05-05 Thread Jeff Newmiller
Read ?history.

Seems somewhat platform dependent, but they ARE different. 
-- 
Sent from my phone. Please excuse my brevity.

On May 5, 2017 7:23:14 AM PDT, Ralf Goertz  wrote:
>Am Fri, 05 May 2017 07:14:36 -0700
>schrieb Jeff Newmiller :
>
>> R normally prompts you to save .RData, but it just automatically
>> saves .Rhistory... the two are unrelated. 
>
>Not here. If I say "n" to the prompted question "Save workspace image?
>[y/n/c]: " my history doesn't get saved.
>
>Version:
>
>R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
>Copyright (C) 2016 The R Foundation for Statistical Computing
>Platform: x86_64-suse-linux-gnu (64-bit)

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] loading edited functions already in saved workspace automatically

2017-05-05 Thread Ralf Goertz
Am Fri, 05 May 2017 07:14:36 -0700
schrieb Jeff Newmiller :

> R normally prompts you to save .RData, but it just automatically
> saves .Rhistory... the two are unrelated. 

Not here. If I say "n" to the prompted question "Save workspace image?
[y/n/c]: " my history doesn't get saved.

Version:

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-suse-linux-gnu (64-bit)

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] loading edited functions already in saved workspace automatically

2017-05-05 Thread Jeff Newmiller
R normally prompts you to save .RData, but it just automatically saves 
.Rhistory... the two are unrelated. 
-- 
Sent from my phone. Please excuse my brevity.

On May 5, 2017 6:44:50 AM PDT, Ralf Goertz  wrote:
>Am Fri, 05 May 2017 06:30:01 -0700
>schrieb Jeff Newmiller :
>
>> The answer most people seem to use is to avoid depending on functions
>> in RData files, and in particular avoiding ever saving the
>> "automatic" ".RData" files at all. (Some people avoid using any RData
>> files, but the automatic loading of functions by ".RData" files is a
>> particularly pernicious source of evil as you have already
>> discovered.)
>> 
>> That is,  always work toward building scripts that you run to restore
>> your workspace rather than depending on save files. Don't depend on
>> save files to keep track of what you do interactively. This also
>> usually means that there should be little if anything in
>> your .Rprofile because that tends to build non-reproducibility into
>> your scripts.
>
>Hi Jeff,
>
>thanks for your answer. Actually, I don't use the workspace saving
>feature primarily for the data but for the command line history. Is
>there a way to just save .Rhistory?
>
>Ralf

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] loading edited functions already in saved workspace automatically

2017-05-05 Thread Ralf Goertz
Am Fri, 05 May 2017 06:30:01 -0700
schrieb Jeff Newmiller :

> The answer most people seem to use is to avoid depending on functions
> in RData files, and in particular avoiding ever saving the
> "automatic" ".RData" files at all. (Some people avoid using any RData
> files, but the automatic loading of functions by ".RData" files is a
> particularly pernicious source of evil as you have already
> discovered.)
> 
> That is,  always work toward building scripts that you run to restore
> your workspace rather than depending on save files. Don't depend on
> save files to keep track of what you do interactively. This also
> usually means that there should be little if anything in
> your .Rprofile because that tends to build non-reproducibility into
> your scripts.

Hi Jeff,

thanks for your answer. Actually, I don't use the workspace saving
feature primarily for the data but for the command line history. Is
there a way to just save .Rhistory?

Ralf

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] loading edited functions already in saved workspace automatically

2017-05-05 Thread Jeff Newmiller
The answer most people seem to use is to avoid depending on functions in RData 
files, and in particular avoiding ever saving the "automatic" ".RData" files at 
all. (Some people avoid using any RData files, but the automatic loading of 
functions by ".RData" files is a particularly pernicious source of evil as you 
have already discovered.)

That is,  always work toward building scripts that you run to restore your 
workspace rather than depending on save files. Don't depend on save files to 
keep track of what you do interactively. This also usually means that there 
should be little if anything in your .Rprofile because that tends to build 
non-reproducibility into your scripts.
-- 
Sent from my phone. Please excuse my brevity.

On May 5, 2017 1:33:27 AM PDT, Ralf Goertz  wrote:
>Hi,
>
>In short: Is it possible to have the previously saved workspace
>restored
>and nevertheless load a function already existing in this workspace via
>.Rprofile anyway?
>
>In detail: I use different directories for different projects. In all
>those projects I use a function which I therefore try to get into the
>session by `myfunc=eval(parse(file=("~/R/myfunc.R")))' in ~/.Rprofile.
>Once I leave the session thereby saving the workspace this function
>gets
>saved in ./.RData as well. In a subsequent session in that directory it
>gets loaded back. However, in the meantime I might have edited
>~/R/myfunc.R. I don't seem to be able to automatically load the new
>function into the session. The workspace gets loaded *after* the
>execution of ~/.Rprofile. So the new definition of myfunc() gets
>overwritten by the old one. I can't use .First() – which is executed
>after loading the workspace – because this would load myfunc() into the
>environment of .First() instead of the global environment. I could use
>.Last() to remove the function before saving the workspace. But then
>.Last() gets saved to the workspace which is also not convenient since
>when I add another function the same way and edit the definition of
>.Last() in ~/.Rprofile to also remove that function this does not work
>because I don't get the new .Last() into the session automatically. And
>no, removing .Last() from within .Last() doesn't work.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

[R] loading edited functions already in saved workspace automatically

2017-05-05 Thread Ralf Goertz
Hi,

In short: Is it possible to have the previously saved workspace restored
and nevertheless load a function already existing in this workspace via
.Rprofile anyway?

In detail: I use different directories for different projects. In all
those projects I use a function which I therefore try to get into the
session by `myfunc=eval(parse(file=("~/R/myfunc.R")))' in ~/.Rprofile.
Once I leave the session thereby saving the workspace this function gets
saved in ./.RData as well. In a subsequent session in that directory it
gets loaded back. However, in the meantime I might have edited
~/R/myfunc.R. I don't seem to be able to automatically load the new
function into the session. The workspace gets loaded *after* the
execution of ~/.Rprofile. So the new definition of myfunc() gets
overwritten by the old one. I can't use .First() – which is executed
after loading the workspace – because this would load myfunc() into the
environment of .First() instead of the global environment. I could use
.Last() to remove the function before saving the workspace. But then
.Last() gets saved to the workspace which is also not convenient since
when I add another function the same way and edit the definition of
.Last() in ~/.Rprofile to also remove that function this does not work
because I don't get the new .Last() into the session automatically. And
no, removing .Last() from within .Last() doesn't work.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.