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

From: Michael H. Prager <Mike.Prager_at_noaa.gov>
Date: Sat 03 Jun 2006 - 06:27:26 EST

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.

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Jun 03 06:39:22 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 03 Jun 2006 - 08:10:43 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.