Browse files

as.package: remove use of ~/.Rpackages, and better error message

  • Loading branch information...
1 parent 3884759 commit 38fd5d10982dd6d751594bd8e55a42b42fd8a7df @wch wch committed Aug 10, 2012
Showing with 12 additions and 33 deletions.
  1. +11 −32 R/package.r
  2. +1 −1 man/as.package.Rd
View
43 R/package.r
@@ -3,7 +3,6 @@
#' Possible specifications of package:
#' \itemize{
#' \item path
-#' \item name (lookup in .Rpackages)
#' \item package object
#' }
#' @param x object to coerce to a package
@@ -20,9 +19,6 @@ as.package <- function(x = NULL) {
}
path <- find_package(x)
- if (is.null(path)) {
- stop("Can't find package ", x, call. = FALSE)
- }
pkg <- load_pkg_description(path)
set_last_package(pkg)
@@ -44,37 +40,20 @@ local({
})
find_package <- function(x) {
- is_package_path <- function(x) {
- if (is.null(x)) return(FALSE)
-
- desc_path <- file.path(x, "DESCRIPTION")
- file.exists(x) && file.exists(desc_path)
- }
- if (is_package_path(x)) {
- return(x)
- }
+ if (is.null(x)) return(FALSE)
- # Look for config file, and give up if it doesn't exist
- config_path <- path.expand("~/.Rpackages")
- if (!file.exists(config_path)) {
- return(NULL)
- }
- lookup <- source(config_path)$value
-
- # Try special case
- if (is_package_path(lookup[[x]])) {
- return(lookup[[x]])
- }
+ # Strip trailing slashes (needed only for windows)
+ x <- normalizePath(x, mustWork = FALSE)
+ x <- gsub("\\\\$", "", x)
- # Otherwise try default function, if it exists
- if (!is.null(lookup$default)) {
- default_loc <- lookup$default(x)
- if (is_package_path(default_loc)) {
- return(default_loc)
- }
- }
+ desc_path <- file.path(x, "DESCRIPTION")
- NULL
+ if ( file.exists(x) && file.exists(desc_path)) {
+ return(x)
+ } else {
+ stop("Can't find package at '", file.path(normalizePath("."), x)
+ , "'", call. = FALSE)
+ }
}
#' Load package DESCRIPTION into convenient form.
View
2 man/as.package.Rd
@@ -9,6 +9,6 @@
}
\description{
Possible specifications of package: \itemize{ \item path
- \item name (lookup in .Rpackages) \item package object }
+ \item package object }
}

0 comments on commit 38fd5d1

Please sign in to comment.