[Sciviews-commits] r299 - in pkg/svMisc: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Sep 7 20:14:13 CEST 2010
Author: phgrosjean
Date: 2010-09-07 20:14:12 +0200 (Tue, 07 Sep 2010)
New Revision: 299
Added:
pkg/svMisc/R/pkg.R
pkg/svMisc/R/systemFile.R
pkg/svMisc/man/Sys.tempdir-deprecated.Rd
pkg/svMisc/man/Sys.userdir-deprecated.Rd
pkg/svMisc/man/pkg.Rd
pkg/svMisc/man/r-deprecated.Rd
pkg/svMisc/man/systemFile.Rd
Removed:
pkg/svMisc/R/Sys.tempdir.R
pkg/svMisc/R/Sys.userdir.R
pkg/svMisc/R/r.R
pkg/svMisc/man/Sys.tempdir.Rd
pkg/svMisc/man/Sys.userdir.Rd
pkg/svMisc/man/r.Rd
Modified:
pkg/svMisc/NAMESPACE
pkg/svMisc/NEWS
pkg/svMisc/man/listTypes.Rd
Log:
Further reworking of svMisc: Sys.tempdir() and Sys.userdir() deprecated in favor of systemDir() and systemFile(),
and r() deprecated in favor of pkg().
Modified: pkg/svMisc/NAMESPACE
===================================================================
--- pkg/svMisc/NAMESPACE 2010-09-07 11:07:37 UTC (rev 298)
+++ pkg/svMisc/NAMESPACE 2010-09-07 18:14:12 UTC (rev 299)
@@ -48,12 +48,15 @@
objSearch,
Parse,
parseText,
+ pkg,
progress,
r,
rmTemp,
sourceClipboard,
Sys.tempdir,
Sys.userdir,
+ systemFile,
+ systemDir,
TempEnv,
tempvar,
toRjson,
Modified: pkg/svMisc/NEWS
===================================================================
--- pkg/svMisc/NEWS 2010-09-07 11:07:37 UTC (rev 298)
+++ pkg/svMisc/NEWS 2010-09-07 18:14:12 UTC (rev 299)
@@ -21,6 +21,12 @@
* For listTypes(), the convention has changed. Method/type is now separated by
an underscore instead as with two dots (like in view_text.default).
+
+* Sys.tempdir() and Sys.userdir() are deprecated in favor of the new more
+ general functions systemFile() and systemDir().
+
+* r() is deprecated in favor of pkg() (r is not informative enough and more
+ susceptible to be used elsewere too).
== Changes in svMisc 0.9-59
Deleted: pkg/svMisc/R/Sys.tempdir.R
===================================================================
--- pkg/svMisc/R/Sys.tempdir.R 2010-09-07 11:07:37 UTC (rev 298)
+++ pkg/svMisc/R/Sys.tempdir.R 2010-09-07 18:14:12 UTC (rev 299)
@@ -1,8 +0,0 @@
-Sys.tempdir <- function ()
-{
- ## On the contrary to tempdir(), this function returns the temporary
- ## directory used by the system. It is assumed to be
- ## the parent directory of tempdir()
- ## TODO: shouldn't we return /tmp on Mac OS X???
- return(dirname(tempdir()))
-}
Deleted: pkg/svMisc/R/Sys.userdir.R
===================================================================
--- pkg/svMisc/R/Sys.userdir.R 2010-09-07 11:07:37 UTC (rev 298)
+++ pkg/svMisc/R/Sys.userdir.R 2010-09-07 18:14:12 UTC (rev 299)
@@ -1,2 +0,0 @@
-Sys.userdir <- function ()
- return(tools::file_path_as_absolute("~"))
Added: pkg/svMisc/R/pkg.R
===================================================================
--- pkg/svMisc/R/pkg.R (rev 0)
+++ pkg/svMisc/R/pkg.R 2010-09-07 18:14:12 UTC (rev 299)
@@ -0,0 +1,32 @@
+r <- function (...) {
+ .Deprecated("pkg")
+ ## r() was not informative enough and is used also in other packages (Distr)
+ return(pkg(...))
+}
+
+pkg <- function (..., warn = TRUE)
+{
+ ## A multiple require proceeding as silently as possible
+ ## Suppress packages messages as much as possible
+ owarn <- getOption("warn")
+ options(warn = -1) # Suppress warnings
+ on.exit(options(warn = owarn))
+ args <- unlist(list(...))
+ l <- length(args)
+ check <- rep(TRUE, l)
+ if (l > 0)
+ for (i in 1:l)
+ check[i] <- suppressPackageStartupMessages(require(args[i],
+ quietly = TRUE, character.only = TRUE, warn.conflicts = FALSE))
+ if (!all(check) && isTRUE(warn)) {
+ bads <- args[!check]
+ options(warn = owarn)
+ if (length(bads) == 1) {
+ warning("Unable to load package ", bads, "!\n")
+ } else {
+ warning("Unable to load package(s): ",
+ paste(bads, collapse = ", "), "!\n")
+ }
+ }
+ return(invisible(check))
+}
Deleted: pkg/svMisc/R/r.R
===================================================================
--- pkg/svMisc/R/r.R 2010-09-07 11:07:37 UTC (rev 298)
+++ pkg/svMisc/R/r.R 2010-09-07 18:14:12 UTC (rev 299)
@@ -1,25 +0,0 @@
-r <- function (...)
-{
- ## A multiple require proceeding as silently as possible
- ## Suppress packages messages as much as possible
- owarn <- getOption("warn")
- options(warn = -1) # Suppress warnings
- on.exit(options(warn = owarn))
- args <- unlist(list(...))
- l <- length(args)
- check <- rep(TRUE, l)
- if (l > 0)
- for (i in 1:l)
- check[i] <- suppressPackageStartupMessages(require(args[i],
- quietly = TRUE, character.only = TRUE, warn.conflicts = FALSE))
- if (!all(check)) {
- bads <- args[!check]
- if (length(bads) == 1) {
- cat("Unable to load package ", bads, "!\n", sep = "")
- } else {
- cat("Unable to load package(s): ",
- paste(bads, collapse = ", "), "!\n", sep = "")
- }
- }
- return(invisible(all(check)))
-}
Added: pkg/svMisc/R/systemFile.R
===================================================================
--- pkg/svMisc/R/systemFile.R (rev 0)
+++ pkg/svMisc/R/systemFile.R 2010-09-07 18:14:12 UTC (rev 299)
@@ -0,0 +1,75 @@
+Sys.tempdir <- function ()
+{
+ .Deprecated("systemDir")
+ return(systemDir("sysTemp"))
+}
+
+Sys.userdir <- function ()
+{
+ .Deprecated("systemDir")
+ return(systemDir("user"))
+}
+
+systemFile <- function (..., exec = FALSE, package = NULL, lib.loc = NULL)
+{
+ ## First look if exec is TRUE
+ if (isTRUE(exec)) {
+ res <- Sys.which(as.character(unlist(list(...))))
+ if (length(res) == 1) res <- as.character(res)
+ } else if (!is.null(package)) {
+ ## A file in a package
+ res <- system.file(..., package = package, lib.loc = lib.loc)
+ ## Check that this is a directory
+ if (!file_test("-f", res)) res <- ""
+ } else {
+ ## Look if this file exists and is a file
+ file <- as.character(unlist(list(...)))
+ file <- file.path(file)
+ if (file_test("-f", file)) res <- normalizePath(file) else res <- ""
+ }
+ return(res)
+}
+
+systemDir <- function (..., exec = FALSE, package = NULL, lib.loc = NULL)
+{
+ ## First look if exec is TRUE
+ if (isTRUE(exec)) {
+ files <- Sys.which(as.character(unlist(list(...))))
+ ## Note: Sys.which() does not always return "" for items not found!
+ res <- dirname(files)
+ res[res == "."] <- ""
+ if (length(res) > 1) names(res) <- names(files)
+ } else if (!is.null(package)) {
+ ## A directory in a package
+ res <- system.file(..., package = package, lib.loc = lib.loc)
+ ## Check that this is a directory
+ if (!file_test("-d", res)) res <- ""
+ } else {
+ ## A predefined directory
+ which <- as.character(unlist(list(...)))
+
+ ## This is a specific directory
+ getDir <- function (which = c("temp", "sysTemp", "user", "home", "bin",
+ "doc", "etc", "share")) {
+ which = match.arg(which)
+ res <- switch(which,
+ "temp" = tempdir(),
+ "sysTemp" = if (!isWin() && file_test("-d", "/tmp")) "/tmp" else
+ dirname(tempdir()),
+ "user" = tools::file_path_as_absolute("~"),
+ "home" = R.home("home"),
+ "bin" = R.home("bin"),
+ "doc" = R.home("doc"),
+ "etc" = R.home("etc"),
+ "share" = R.home("share"))
+ return(res)
+ }
+ if (is.null(which) || length(which) == 0) return(character(0)) else {
+ res <- character(length(which))
+ if (length(which) > 1) names(res) <- which
+ for (i in seq_along(which))
+ res[i] <- getDir(which[i])
+ }
+ }
+ return(res)
+}
Added: pkg/svMisc/man/Sys.tempdir-deprecated.Rd
===================================================================
--- pkg/svMisc/man/Sys.tempdir-deprecated.Rd (rev 0)
+++ pkg/svMisc/man/Sys.tempdir-deprecated.Rd 2010-09-07 18:14:12 UTC (rev 299)
@@ -0,0 +1,24 @@
+\name{Sys.tempdir}
+\alias{Sys.tempdir}
+
+\title{ Get the system temporary directory }
+\description{
+ This function is deprecated in favor of \code{systemDir("sysTemp")}!
+ \code{Sys.tempdir()} retrieves the system temporary directory, which is
+ usually /tmp under Unix, but could be located elsewhere, especially under
+ Windows. It is simply the root directory of \code{tempdir()}.
+}
+
+\usage{
+Sys.tempdir()
+}
+
+\value{
+ A string with the path to the system temporary directory.
+}
+
+\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
+
+\seealso{ \code{\link{systemDir}} }
+
+\keyword{ utilities }
Deleted: pkg/svMisc/man/Sys.tempdir.Rd
===================================================================
--- pkg/svMisc/man/Sys.tempdir.Rd 2010-09-07 11:07:37 UTC (rev 298)
+++ pkg/svMisc/man/Sys.tempdir.Rd 2010-09-07 18:14:12 UTC (rev 299)
@@ -1,29 +0,0 @@
-\name{Sys.tempdir}
-\alias{Sys.tempdir}
-
-\title{ Get the system temporary directory }
-\description{
- \code{Sys.tempdir()} retrieves the system temporary directory, which is
- usually /tmp under Unix, but could be located elsewhere, especially under
- Windows. It is simply the root directory of \code{tempdir()}.
-}
-
-\usage{
-Sys.tempdir()
-}
-
-\value{
- A string with the path to the system temporary directory.
-}
-
-\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
-
-\seealso{ \code{\link{Sys.userdir}} }
-
-\examples{
-Sys.tempdir()
-}
-
-\keyword{ utilities }
-
-\concept{ system directories }
Added: pkg/svMisc/man/Sys.userdir-deprecated.Rd
===================================================================
--- pkg/svMisc/man/Sys.userdir-deprecated.Rd (rev 0)
+++ pkg/svMisc/man/Sys.userdir-deprecated.Rd 2010-09-07 18:14:12 UTC (rev 299)
@@ -0,0 +1,22 @@
+\name{Sys.userdir}
+\alias{Sys.userdir}
+
+\title{ Get the user directory }
+\description{
+ This function is deprecated in favor of \code{systemDir("user")}!
+ \code{Sys.userdir()} retrieves the current user directory.
+}
+
+\usage{
+Sys.userdir()
+}
+
+\value{
+ A string with the path to the user directory.
+}
+
+\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
+
+\seealso{ \code{\link{systemDir}} }
+
+\keyword{ utilities }
Deleted: pkg/svMisc/man/Sys.userdir.Rd
===================================================================
--- pkg/svMisc/man/Sys.userdir.Rd 2010-09-07 11:07:37 UTC (rev 298)
+++ pkg/svMisc/man/Sys.userdir.Rd 2010-09-07 18:14:12 UTC (rev 299)
@@ -1,25 +0,0 @@
-\name{Sys.userdir}
-\alias{Sys.userdir}
-
-\title{ Get the user directory }
-\description{
- \code{Sys.userdir()} retrieves the current user directory.
-}
-\usage{
-Sys.userdir()
-}
-
-\value{
- A string with the path to the user directory.
-}
-\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
-
-\seealso{ \code{\link{Sys.tempdir}} }
-
-\examples{
-Sys.userdir()
-}
-
-\keyword{ utilities }
-
-\concept{ system directories }
Modified: pkg/svMisc/man/listTypes.Rd
===================================================================
--- pkg/svMisc/man/listTypes.Rd 2010-09-07 11:07:37 UTC (rev 298)
+++ pkg/svMisc/man/listTypes.Rd 2010-09-07 18:14:12 UTC (rev 299)
@@ -8,6 +8,7 @@
to a usual \code{type =} or \code{which =} argument, like in \code{plot.ts()}
or \code{plot.lm()}, respectively.
}
+
\usage{
listTypes(method, class = "default", strict = FALSE)
}
@@ -19,9 +20,11 @@
possible types, including for inherited objects, and default ones
(\code{FALSE}, by default)? }
}
+
\value{
A vector with character strings with methods' type names.
}
+
\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
\note{ This function is only useful for special generic functions with type
@@ -39,3 +42,5 @@
}
\keyword{ utilities }
+
+\concept{ Method dispatching }
Added: pkg/svMisc/man/pkg.Rd
===================================================================
--- pkg/svMisc/man/pkg.Rd (rev 0)
+++ pkg/svMisc/man/pkg.Rd 2010-09-07 18:14:12 UTC (rev 299)
@@ -0,0 +1,40 @@
+\name{pkg}
+\alias{pkg}
+
+\title{ A very silent and multipackage require() function }
+\description{
+ This function loads one or several R packages as silently as possible and
+ it returns \code{TRUE} only if all packages are loaded successfully. If
+ at least one loading fails, a short message is printed.
+}
+\usage{
+ pkg(..., warn = TRUE)
+}
+
+\arguments{
+ \item{\dots}{ the name of one or several R packages to load (character
+ strings). }
+ \item{warn}{ If \code{TRUE}, issue a warning if one or several packages are
+ not loaded. }
+}
+
+\value{
+ \code{TRUE} if all packages are loaded correctly, \code{FALSE} otherwise. This
+ function is designed to concisely and quitely indicate package requirements in
+ GUI menu or other GUI actions.
+}
+
+\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
+
+\seealso{ \code{\link[base]{require}} }
+
+\examples{
+## This should work...
+if (all(pkg("tools", "methods"))) cat("Fine!\n")
+## ... but this not
+if (!all(pkg("tools", "badname", warn = FALSE))) cat("Not fine!\n")
+}
+
+\keyword{ utilities }
+
+\concept{ package requirement and loading }
Added: pkg/svMisc/man/r-deprecated.Rd
===================================================================
--- pkg/svMisc/man/r-deprecated.Rd (rev 0)
+++ pkg/svMisc/man/r-deprecated.Rd 2010-09-07 18:14:12 UTC (rev 299)
@@ -0,0 +1,31 @@
+\name{r}
+\alias{r}
+
+\title{ A very silent and multipackage require() function }
+\description{
+ This function is deprecated in favor of \code{pkg()} (more informative
+ name that is less susceptible to be used elsewhere)!
+ This function loads one or several R packages as silently as possible and
+ it returns \code{TRUE} only if all packages are loaded successfully. If
+ at least one loading fails, a short message is printed.
+}
+\usage{
+ r(...)
+}
+
+\arguments{
+ \item{\dots}{ the name of one or several R packages to load (character
+ strings). }
+}
+
+\value{
+ \code{TRUE} if all packages are loaded correctly, \code{FALSE} otherwise. This
+ function is designed to concisely and quietly indicate package requirements in
+ GUI menu or other GUI actions.
+}
+
+\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
+
+\seealso{ \code{\link{pkg}} }
+
+\keyword{ utilities }
Deleted: pkg/svMisc/man/r.Rd
===================================================================
--- pkg/svMisc/man/r.Rd 2010-09-07 11:07:37 UTC (rev 298)
+++ pkg/svMisc/man/r.Rd 2010-09-07 18:14:12 UTC (rev 299)
@@ -1,38 +0,0 @@
-\name{r}
-\alias{r}
-
-\title{ A very silent and multipackage require() function }
-\description{
- This function loads one or several R packages as silently as possible and
- it returns \code{TRUE} only if all packages are loaded successfully. If
- at least one loading fails, a short message is printed.
-}
-\usage{
- r(...)
-}
-
-\arguments{
- \item{\dots}{ the name of one or several R packages to load (character
- strings). }
-}
-
-\value{
- \code{TRUE} if all packages are loaded correctly, \code{FALSE} otherwise. This
- function is designed to concisely and quitely indicate package requirements in
- GUI menu or other GUI actions.
-}
-
-\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
-
-\seealso{ \code{\link[base]{require}} }
-
-\examples{
-## This should work...
-if (r("tools", "methods")) cat("Fine!\n")
-## ... but this not (notice there is no error or warning!)
-if (r("tools", "badname")) cat("Fine!\n")
-}
-
-\keyword{ utilities }
-
-\concept{ package requirement and loading }
Added: pkg/svMisc/man/systemFile.Rd
===================================================================
--- pkg/svMisc/man/systemFile.Rd (rev 0)
+++ pkg/svMisc/man/systemFile.Rd 2010-09-07 18:14:12 UTC (rev 299)
@@ -0,0 +1,69 @@
+\name{systemFile}
+\alias{systemFile}
+\alias{systemDir}
+
+\title{ Get a system file or directory }
+\description{
+ Get system files or directories, in R subdirectories, in package
+ subdirectories, or elsewhere on the disk (including executables that are
+ accessible on the search path).
+}
+
+\usage{
+systemFile(\dots, exec = FALSE, package = NULL, lib.loc = NULL)
+systemDir(\dots, exec = FALSE, package = NULL, lib.loc = NULL)
+}
+
+\arguments{
+ \item{\dots}{ one or several executables if \code{exec = TRUE}, or subpath to
+ a file or dir in a package directory if \code{package != NULL}, or a list of
+ path and subpaths for testing the existence of a file on disk, or a list of
+ directory components to retrieve in 'temp', 'sysTemp', 'user', 'home',
+ 'bin', 'doc', 'etc' and/or 'share' to retrieve special system directories. }
+ \item{exec}{ if \code{TRUE} (default) search for executables on the search
+ path. It superseedes all other arguments. }
+ \item{package}{ the name of one package to look for files or subdirs in its
+ main directory (use \code{exec = FALSE} to search inside package dirs). }
+ \item{lib.loc}{ a character vector with path names of \R libraries or
+ \code{NULL} (search all currently known libraries in this case). }
+}
+
+\value{
+ A string with the path to the directories or files, or \code{""} if they are
+ not found, or of the wrong type (a dir for \code{systemFile()} or or a file
+ for \code{systemDir()}).
+}
+
+\note{
+ These function aggregate the features of several \R functions in package
+ base: system.file(), R.home(), tempdir(), Sys.which(), and aim to provide a
+ unified and convenient single interface to all of them. We make sure also to
+ check that returned components are respectively directories and files for
+ \code{systemDir()} and \code{systemFile()}.
+}
+
+\author{ Philippe Grosjean <phgrosjean at sciviews.org> }
+
+\seealso{ \code{\link[base]{file.path}}, \code{\link[base]{file.exists}} }
+
+\examples{
+systemFile("INDEX", package = "base")
+systemFile("help", "AnIndex", package = "splines")
+systemFile(package = "base") # This is a dir, not a file!
+systemFile("zip", exec = TRUE)
+systemFile("ftp", "ping", "zip", "nonexistingexe", exec = TRUE)
+systemDir("temp") # The R temporary directory
+systemDir("sysTemp") # The system temporary directory
+systemDir("user") # The user directory
+systemDir("home", "bin", "doc", "etc", "share") # Various R dirs
+systemDir("zip", exec = TRUE) # Look for the dir of an executable
+systemDir("ftp", "ping", "zip", "nonexistingexe", exec = TRUE)
+systemDir(package = "base") # The root of the 'base' package
+systemDir(package = "stats") # The root of package 'stats'
+systemDir("INDEX", package = "stats") # This is a file, not a dir!
+systemDir("help", package = "splines")
+}
+
+\keyword{ utilities }
+
+\concept{ system files and directories }
More information about the Sciviews-commits
mailing list