[R] loading edited functions already in saved workspace automatically

Michael Friendly friendly at yorku.ca
Sat May 6 17:17:42 CEST 2017


On 5/5/2017 10:23 AM, Ralf Goertz wrote:
> Am Fri, 05 May 2017 07:14:36 -0700
> schrieb Jeff Newmiller <jdnewmil at dcn.davis.ca.us>:
>
>> 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 Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA



More information about the R-help mailing list