Install from S-PLUS Source Files into a Package

DESCRIPTION:

The function installFromSFiles installs S-PLUS objects from source files into a package while running S-PLUS.

USAGE:

installFromSFiles(files, where, clean.first=FALSE, sourcedir, extensions, 
    verbose=TRUE)
installFromDataFiles(files, where, clean.first = FALSE, sourcedir, extensions, 
    verbose=TRUE)
redirectGlobalAssignments(expr, where, enter.expression=TRUE)

REQUIRED ARGUMENTS:

files
a character vector of the names of files containing S-PLUS functions or other object definitions to be installed.
where
a character string with the package name or the path name to the package directory, or an integer specifying the position of the attached package in the search list. The package directory can be attached or unattached. If unattached, it must be attachable (at least contain .Data and .Data/__Meta directories). If attached, installFromSFiles will temporarily override the read-only status assigned by the library() command.
expr
a S-PLUS expression resulting from a call to parse.

OPTIONAL ARGUMENTS:

clean.first
a logical value indicating whether or not to delete all of the objects in the package before installing the new objects. The default value is FALSE.
sourcedir
the directory containing the source files.
extensions
the relevant file extensions in the source directory.
For installFromSFiles, can be any of the following:
S, R, ssc, SSC, q
For installFromDataFiles, can be any of the following:
csv, CSV, tab, TAB, txt, TXT, S, R, ssc, SSC, q, rda, rdata, RData
verbose
a logical value. If TRUE, provides detailed information about the installation.
enter.expression
a logical value used by function redirectGlobalAssignments to indicate if objects of mode expression should be searched for assignments such as <-, assign, and setMethod. The default value is TRUE.

VALUE:

This function is used for its side effects. The value of installFromSFiles is the useless value vector("missing",0).

The function redirectGlobalAssignments returns an expression similar to the input expression but with where=where in all assignments.

DETAILS:

The package directory specified by the where= argument must already exist. It can be attached or unattached.

Source files can be created using S-PLUS functions such as dump() , dumpMethods(), and package.skeleton()

Some assignments, such as a<-b<-value and x$name<-value , are hard to handle and may cause errors.

The function installFromDataFiles reads the data files in a package and stores them in its .Data directory. You can pass in either a list of files or a source directory and the names of the relevant file extensions in the source directory.

The function redirectGlobalAssignments is called by installFromSFiles to change global assignments in an expression to use where=where instead of the implicit where=1 or an explicit setting of where in assignments. This function is primarily for internal use.

SEE ALSO:

, , .
Read the Guide to S-PLUS Packages manual for more details.

EXAMPLES:

# Create an attachable directory, then install objects from source files
testdir <- tempfile()
createChapter(testdir)
# put some assignments into a source file
file2=file.path(testdir, "newFunc2.q")
cat(c("{ newFunc2<-function(x)x+1",
  "setGeneric(\"newFunc2\", function(x)standardGeneric(\"newFunc2\"), where=\"DEST\")",
  "setMethod(\"newFunc2\", \"character\", function(x)toupper(x)) }") , 
  file=file2, fill=T)
# install from the source file and verify
installFromSFiles(files=file2, where=testdir)
attach(testdir)
cat(newFunc2("a"),newFunc2(12), sep=":", fill=T)
rmdir(testdir)

# Create a new package, then install objects from new source files
testdir <- tempfile()
mkdir(testdir)
newFunc0 <- function(x) newFunc1(x) 
newFunc1 <- function(x) log(x)
# create a new package
library(pkgutils)
pkgname <- "testPackage"
package.skeleton(name=pkgname, list=c("newFunc0","newFunc1"), 
        path=testdir, force=FALSE)
pkgdir <- file.path(testdir, pkgname)
createChapter(pkgdir)
library(eval(pkgname), lib.loc=testdir)
rm("newFunc0","newFunc1")
# install the newly created source file(s)
installFromSFiles(files=list.files(file.path(packagedir,"R"), full.names=T),
        where=pkgname)
# verify that everything is there
objects(where=pkgname)
newFunc1(exp(10))
detach(pkgname)
rmdir(testdir)

# Returns the expression modified so that all assignments
# are to the "MY_PACKAGE" directory.
z <- redirectGlobalAssignments(where="MY_PACKAGE", Quote(
   { f<-function(x)x+1
     setGeneric("f", function(x)standardGeneric("f"), where="DEST")
     setMethod("f", "character", function(x)toupper(x)) }))
z