Skip to content

Commit

Permalink
Updated p_delete to actually find the location of the library locat…
Browse files Browse the repository at this point in the history
…ion for each package.

Updated documentation (thinks like adding \code{TRUE})

`Added XML to importFrom and fixed in p_search_any`, `p_help`

Removed unnecessary `cat`s
  • Loading branch information
trinker committed Feb 5, 2014
1 parent 6cd052f commit 1f2d53a
Show file tree
Hide file tree
Showing 39 changed files with 287 additions and 207 deletions.
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ Title: Package Management Tool
Version: 0.2.0
Date: 2012-06-03
Authors@R: c(person("Tyler", "Rinker",
role = c("aut", "cre", "ctb"),
email = "[email protected]"),
role = c("aut", "cre", "ctb"),
email = "[email protected]"),
person("Dason", "Kurkiewicz",
role = c("aut", "ctb"),
email = "[email protected]"))
role = c("aut", "ctb"),
email = "[email protected]"))
Author: Tyler Rinker & Dason Kurkiewicz
Maintainer: Tyler Rinker <[email protected]>
Depends:
R (>= 2.13.0)
Suggests:
lattice,
Imports:
XML
Suggests:
lattice
BugReports: https://github.com/trinker/pacman/issues?state=open
Description: This package is a designed to more conveniently perform tasks
associated with add on packages. pacman conveniently wraps library and
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ export(p_version)
export(p_vign)
export(p_vignette)
export(p_zip)
importFrom(XML,getNodeSet)
importFrom(XML,htmlTreeParse)
importFrom(XML,readHTMLTable)
importFrom(XML,xmlValue)
2 changes: 1 addition & 1 deletion R/p_author.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
p_author <-
function(package = "base"){
x <- as.character(substitute(package))
packageDescription(x)$Author
packageDescription(x)[["Author"]]
}
13 changes: 7 additions & 6 deletions R/p_base.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#' List all the packages in a base install
#'
#' List all the packages in a base install
#' List all the packages and marks those in a base install
#'
#' @param open logical. If TRUE opens the directory of the base install packages
#' @param basemarker character string. The string to append to mark which packages
#' are part of the default packages.
#' @note Packages that are installed when R starts are marked with an asterisk(*)
#' @param open logical. If \code{TRUE} opens the directory of the base install
#' packages.
#' @param basemarker character string. The string to append to mark which
#' packages are part of the default packages.
#' @note Packages that are installed when R starts are marked with an asterisk(*).
#' @seealso \code{\link[base]{getOption}}
#' @keywords base package
#' @export
Expand All @@ -28,7 +29,7 @@ function(open = FALSE, basemarker = "***"){
if (open) {
p_opendir(basepath)
}
cat('\npackages with an', basemarker, 'are loaded when R starts\n\n')
message('\npackages with an', basemarker, 'are loaded when R starts\n\n')
print(noquote(modified_output))
invisible(basefiles)
}
32 changes: 30 additions & 2 deletions R/p_citation.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#'
#' @rdname p_citation
#' @param package Name of the package you want a citation for
#' @param copy2clip logical. If TRUE attempts to copy the output to the
#' @param copy2clip logical. If \code{TRUE} attempts to copy the output to the
#' clipboard
#' @param tex logical. If \code{TRUE} A only the BibTex version of the citation
#' is copied to the clipboard. If \code{FALSE} The standard citation is copied
#' to the clipboard. If \code{NULL} both are copied to the clipboard.
#' @param \ldots Additional inputs to \code{\link[utils]{citation}}
#' @seealso \code{\link[utils]{citation}}
#' @keywords citation cite
Expand All @@ -14,15 +17,40 @@
#' p_citation()
#' p_cite(pacman)
#' p_citation(pacman)
p_citation <- function(package = "r", copy2clip = TRUE, ...) {
p_citation <- function(package = "r", copy2clip = TRUE, tex = TRUE, ...) {
x <- as.character(substitute(package))

if(x %in% c("R", "r")){
# To cite R we need to use package = "base"
x <- "base"
}

if(copy2clip){
## Grab citation to optionally manipulate
## and copy to clipboard
out <- capture.output(citation(package = x, ...))

if (!is.null(tex)) {

loc <- grep("BibTeX entry for LaTeX", out)

if (isTRUE(tex)) {
## Grab only the bibtex portion
locs <- (1 + loc):length(out)
} else {

## Remove the `To cite in publications, please use:`
grab <- seq_along(out) != grep("in publications, please use", out)
out <- out[grab]

## Grab only the standard portion
locs <- 1:(loc - 1)
}

out <- out[locs]
out <- out[out != ""]
out <- paste(substring(out, 3), collapse="\n")
}
writeToClipboard(out)
}
citation(package = x, ...)
Expand Down
4 changes: 2 additions & 2 deletions R/p_cran.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#'
#' Generate a vector of all available packages.
#'
#' @param menu logical. If TRUE allows user to select
#' the package and return that package name
#' @param menu logical. If \code{TRUE} allows user to select the package and
#' return that package name.
#' @seealso \code{\link[utils]{available.packages}}
#' @keywords CRAN package
#' @export
Expand Down
8 changes: 4 additions & 4 deletions R/p_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#'
#' Generate a script of all data sets contained in package.
#'
#' @param package name of package (default is the base install datasets package)
#' @param static logical. If TRUE a static txt docuemnt is returned (e.g.
#' \code{data("datasets")}).
#' @param package name of package (default is the base install datasets package).
#' @param static logical. If \code{TRUE} a static text docuemnt is returned
#' (e.g. \code{data("datasets")}).
#' @seealso \code{\link[utils]{data}}
#' @return Returns the data sets of a package as dataframe
#' (\code{static = FALSE}) or as a static txt file (\code{static = TRUE}).
#' (\code{static = FALSE}) or as a static text file (\code{static = TRUE}).
#' @keywords data package
#' @export
#' @examples
Expand Down
76 changes: 45 additions & 31 deletions R/p_delete.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,62 @@
#' p_delete(pacman) # You never want to run this
#' }
p_delete <-
function (...)
{
function (...) {
mf <- match.call(expand.dots = FALSE)
x <- as.character(mf[[2]])
lp <- .libPaths()[1]
z <- x[!x %in% dir(lp)]

## TODO: We definitely need to rewrite
## to better detect where the package actually
## is stored
m <- dir(.libPaths()[2])
o <- z[z %in% dir(.libPaths()[2])]
z <- z[!z %in% dir(.libPaths()[2])]
y <- x[x %in% dir(lp)]
y2 <- paste0("package:", y)
w <- y %in% names(sessionInfo()[["otherPkgs"]])
if (any(w)) {
u <- y2[w]
invisible(lapply(u, function(package) {
packs <- as.character(mf[[2]])
pack_check <- sapply(packs, function(x) system.file(package = x))

## Generate list of packages present/absent in a library
absent <- nulls(names(pack_check[pack_check == ""]))
base_install <- rownames(installed.packages(priority="base"))
bcheck <- basename(pack_check) %in% c(base_install)
base <- nulls(basename(pack_check)[bcheck])
present <- nulls(pack_check[!bcheck & pack_check != ""])

## Unload any package that will be deleted
loaded <- basename(present) %in% names(sessionInfo()[["otherPkgs"]])
if (any(loaded)) {
unloads <- sprintf("package:%s", basename(present)[loaded])
invisible(lapply(unloads, function(package) {
suppressWarnings(detach(package, character.only = TRUE,
force = TRUE, unload = TRUE))
}))
}
if (length(y) > 0){
suppressWarnings(remove.packages(y, lib = lp))

## Force delete the files
if (length(present) > 0){
suppressWarnings(remove.packages(pkgs = basename(present),
lib = dirname(present)))
}
y <- paste(y, collapse = ", ")
if (!identical(o, character(0))) {
cat(paste0("The following packages are a base ",
"install and will not be deleted:\n"),
paste0("\b", paste(o, collapse = ", ")), "\n\n")

## Message about base package not removed
if (!is.null(base)) {
message("The following packages are a base ",
"install and will not be deleted:\n",
paste(base, collapse = ", "), "\n")
}
if (!identical(z, character(0))) {
cat("The following packages not found in library:\n",
paste0("\b", paste(z, collapse = ", ")), "\n\n")

## Message about files not found
if (!is.null(absent)) {
message("The following packages not found in library:\n",
paste(absent, collapse = ", "), "\n")
}
if (length(y) > 0) {
cat("The following packages have been deleted:\n", paste0("\b",
paste(y, collapse = ", ")), "\n")

## Message about deleted files
if (length(present) > 0) {
message("The following packages have been deleted:\n",
paste(basename(present), collapse = ", "))
}
}

## Helper to check for as.character(0) and turn to NULL
nulls <- function(x, ret = NULL) {
if (identical(x, character(0))){
x <- ret
}
x
}

#' @rdname p_delete
#' @export
p_del <- p_delete
7 changes: 3 additions & 4 deletions R/p_exists.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#' Checks CRAN to determine if a package exists
#'
#' @param package name of package
#' @param cran logical. If TRUE checks CRAN for the package;
#' if FALSE checks the user's local library
#' @param cran logical. If \code{TRUE} checks CRAN for the package;
#' if \code{FALSE} checks the user's local library.
#' @keywords exists package
#' @export
#' @examples
Expand All @@ -14,8 +14,7 @@
#' p_exists(I_dont_exist)
#' }
p_exists <-
function (package, cran = TRUE)
{
function (package, cran = TRUE) {
x <- as.character(substitute(package))
if (cran){
a <- available.packages()
Expand Down
11 changes: 6 additions & 5 deletions R/p_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#'
#' @rdname p_functions
#' @param package Name of the package you want the list of functions for.
#' @param all logical. If TRUE all of the functions from the package will
#' be displayed regardless of whether they're exported or not.
#' @param load logical. If TRUE loads the package.
#' @param character.only logical. If TRUE the input is a variable
#' @param all logical. If \code{TRUE} all of the functions from the package
#' will be displayed regardless of whether they're exported or not.
#' @param load logical. If \code{TRUE} loads the package.
#' @param character.only logical. If \code{TRUE} the input is a variable
#' containing the package name.
#' @keywords function package
#' @export
Expand Down Expand Up @@ -51,7 +51,8 @@ function (package = "base", all = FALSE, load = FALSE, character.only = FALSE){

## Should we mark non-exported functions with asterisks or something?
if(all){
packagefunctions <- unclass(lsf.str(envir = asNamespace(package), all = T))
packagefunctions <- unclass(lsf.str(envir = asNamespace(package),
all = TRUE))
# Removes pesky attributes.
attributes(packagefunctions) <- NULL
}else{
Expand Down
14 changes: 6 additions & 8 deletions R/p_help.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#'
#' Generate an html, web or pdf of a package's help manual
#'
#' @param package name of package
#' @param web logical. If TRUE grabs current help manual from the web
#' @param pdf logical. If TRUE uses a LaTeX compiler to generate a pdf
#' @param package Name of package.
#' @param web logical. If \code{TRUE} grabs current help manual from the web.
#' @param pdf logical. If \code{TRUE} uses a LaTeX compiler to generate a pdf
#' @section Warning:
#' To use the pdf argument you must have a pdf compiler (e.g. MikTex) installed.
#' @keywords help manual package
#' @seealso \code{\link[utils]{help}}
#' @importFrom XML htmlTreeParse getNodeSet xmlValue
#' @export
#' @examples
#' \dontrun{
Expand All @@ -24,12 +25,9 @@ function (package = NULL, web = FALSE, pdf = FALSE) {
x <- "base"
y <- list.files(.libPaths())
if (web) {
if(!require("XML")){
install.packages("XML")
}
suppressPackageStartupMessages(p_load("XML"))

url <- "http://stat.ethz.ch/R-manual/R-patched/library/"
doc <- XML::htmlTreeParse(url, useInternalNodes = TRUE)
doc <- htmlTreeParse(url, useInternalNodes = TRUE)
content <- getNodeSet(doc, "//pre//text()")
content <- sapply(content, xmlValue)
content <- content[10:length(content)]
Expand Down
9 changes: 4 additions & 5 deletions R/p_interactive.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#' Interactive package exploration
#'
#' Interactively search through packages, looking
#' at functions and optionally attaching the package
#' and looking at the help page.
#' Interactively search through packages, looking at functions and optionally
#' attaching the package and looking at the help page.
#'
#' @rdname p_interactive
#' @keywords package
Expand All @@ -26,14 +25,14 @@ function() {
sep = ""), character.only = TRUE)))
}
y <- menu(objects(paste("package:", pack, sep = "")))
cat("Available Functions\n")
message("Available Functions\n")
fun <- objects(paste("package:", pack, sep = ""))[y]
z2 <- switch(menu(c(cat("\n\nDo you want to see the help page for",
fun, "\b?\n"), "Yes", "No")), TRUE, FALSE)
if (z2) {
help((fun))
}
cat("Thank you for using the p_interactive function!\n\n")
message("Thank you for using the p_interactive function!\n\n")
}

#' @rdname p_interactive
Expand Down
4 changes: 2 additions & 2 deletions R/p_library.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#' packages are stored).
#'
#' @rdname p_library
#' @param open logical. If TRUE opens the directory of
#' the add on packages library.
#' @param open logical. If \code{TRUE} opens the directory of the add on
#' packages library.
#' @keywords library package
#' @export
#' @examples
Expand Down
Loading

0 comments on commit 1f2d53a

Please sign in to comment.