[R] FW: How to create a new package?

Michael H. Prager Mike.Prager at noaa.gov
Fri Jun 2 22:27:26 CEST 2006


To follow up on Bert Gunter's remark about a "quicker and dirtier" way, 
here is the R script I use to source every *.r file in a directory and 
save the results into a workspace.  It excludes any files beginning with 
"00" (for example, itself) from the operations.  This simplifies 
maintaining a collection of user functions that are kept in a single 
directory and frequently updated.

###############################################################
## 00make.r     M.H.Prager      November 2005
## This clears the current workspace, sources all the commands,
## and then saves the workspace for use by all R sessions

# Clear all existing objects in workspace:
rm(list=ls())

# Make a list of all R source files in this directory:
flist = list.files(path=".", pattern=".+\.r")

# Remove from the list all files containing the string "00":
# Such files should be used for temporary funcs:
flist2 = flist[-grep("00",flist)]

# Source the files:
for (i in 1:length(flist2)) {
   cat("Sourcing", flist2[i],"\n")
   source(flist2[i])
   }
# Remove temporary objects:
rm(i,flist,flist2)
# Save workspace:
save.image()
# Write message to user:
cat("\nNOTE: The workspace has been saved with all functions.\n",
    "     When exiting R, please do NOT save again.\n")
ls()
##################################################################

This can be run quickly from a Windows console with

rterm.exe --no-restore --no-save < 00make.r > 00make.txt

...Mike Prager


on 6/1/2006 4:15 PM Berton Gunter said the following:
> Quicker and dirtier is to simply save a workspace  with your desired
> functions and attach() it automatically (e.g. via .First or otherwise) at
> startup (?Startup for details and options). Of course none of the tools and
> benefits of package management are available, but then I did say quicker and
> dirtier.
>
> -- Bert Gunter
> Genentech Non-Clinical Statistics
> South San Francisco, CA
>   

-- 
Michael Prager, Ph.D.
Southeast Fisheries Science Center
NOAA Center for Coastal Fisheries and Habitat Research
Beaufort, North Carolina  28516
** Opinions expressed are personal, not official.  No
** official endorsement of any product is made or implied.



More information about the R-help mailing list