Skip to content

Commit

Permalink
Update to use new dev_packages function
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Aug 20, 2012
1 parent 7352111 commit e5caa8d
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 34 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -70,3 +70,4 @@ Collate:
'imports-env.r'
'namespace-env.r'
'topic-index.r'
'help.r'
2 changes: 1 addition & 1 deletion NAMESPACE
Expand Up @@ -15,6 +15,7 @@ export(clean_source)
export(clean_vignettes)
export(compile_dll)
export(create)
export(dev_example)
export(dev_meta)
export(dev_mode)
export(dev_packages)
Expand Down Expand Up @@ -49,7 +50,6 @@ export(revdep)
export(revdep_check)
export(revdep_maintainers)
export(revdep)
export(run_example)
export(run_examples)
export(set_path)
export(show_news)
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Expand Up @@ -3,6 +3,12 @@
`auth_user` if it's not your package (i.e. it's not your `username`) (Fixes
#116)

* new `dev_help` function replaces `show_rd` and makes it easy to get help on
any topic in a development package (i.e. a package loaded with `load_all`)
(Fixes #110)

* `dev_example` runs the examples for one in-development package. (Fixes #108)

* `create` function makes it easier to create a package skeleton using
devtools standards.

Expand Down
27 changes: 0 additions & 27 deletions R/document.r
Expand Up @@ -61,30 +61,3 @@ check_doc <- function(pkg = NULL) {
# print(tools::checkDocStyle(dir = pkg$path))
# print(tools::undoc(dir = pkg$path))
}


#' Show an Rd file in a package.
#'
#' @param pkg package description, can be path or package name. See
#' \code{\link{as.package}} for more information
#' @param file topic or name Rd file to open.
#' @param ... additional arguments passed onto \code{\link[tools]{Rd2txt}}.
#' This is particular useful if you're checking macros and want to simulate
#' what happens when the package is built (\code{stage = "build"})
#' @export
#' @importFrom tools file_ext
#' @importFrom tools Rd2txt
show_rd <- function(pkg = NULL, file, ...) {
pkg <- as.package(pkg)

rd <- find_topic(pkg, file)
if (is.null(rd)) {
stop("Could not find topic or Rd file ", file, call. = FALSE)
}

path <- file.path(pkg$path, "man", rd)
temp <- Rd2txt(path, out = tempfile("Rtxt"), package = pkg$package,
...)
file.show(temp, title = paste("Dev documentation: ", file),
delete.file = TRUE)
}
57 changes: 57 additions & 0 deletions R/help.r
@@ -0,0 +1,57 @@
#' Read the in-development help for a package loaded with devtools.
#'
#' Note that this only renders a single documentation file, so that links
#' to other files within the package won't work.
#'
#' @param topic name of help to search for.
#' @param stage at which stage (‘"build"’, ‘"install"’, or ‘"render"’) should
#' \\Sexpr macros be executed? This is only important if you're using
#' \\Sexpr macro's in your Rd files.
#' @examples
#' \dontrun{
#' library("ggplot2")
#' help("ggplot") # loads installed documentation for ggplot
#'
#' load_all("ggplot2")
#' dev_help("ggplot") # loads development documentation for ggplot
#' }
dev_help <- function(topic, stage = "render") {
path <- find_topic(topic)
if (is.null(path)) {
dev <- paste(dev_packages(), collapse = ", ")
stop("Could not find topic ", topic, " in: ", dev)
}

view_rd(path, stage = stage)
}

#' Show an Rd file in a package.
#'
#' @param pkg package description, can be path or package name. See
#' \code{\link{as.package}} for more information
#' @param file topic or name Rd file to open.
#' @param ... additional arguments passed onto \code{\link[tools]{Rd2txt}}.
#' This is particular useful if you're checking macros and want to simulate
#' what happens when the package is built (\code{stage = "build"})
#' @export
#' @importFrom tools file_ext
#' @importFrom tools Rd2txt
show_rd <- function(pkg = NULL, file, ...) {
.Deprecated("dev_help")
pkg <- as.package(pkg)

rd <- find_pkg_topic(pkg, file)
if (is.null(rd)) {
stop("Could not find topic or Rd file ", file, call. = FALSE)
}

path <- file.path(pkg$path, "man", rd)
view_rd(path, ...)
}

view_rd <- function(path, package, stage = "render") {
temp <- Rd2txt(path, out = tempfile("Rtxt"), package = "In development",
stages = stage)
file.show(temp, title = paste("Dev documentation: ", basename(path)),
delete.file = TRUE)
}
9 changes: 4 additions & 5 deletions R/run-examples.r
Expand Up @@ -72,16 +72,15 @@ run_one_example <- function(name, rd, pkg, env = parent.frame(), strict = TRUE)
cat("\n\n")
}

#' Run a single example.
#' Run a examples for an in-development function.
#'
#' @inheritParams run_examples
#' @param topic Name or topic (or name of Rd) file to run examples for
#' @export
#' @family example functions
run_example <- function(pkg = NULL, topic, strict = FALSE) {
pkg <- as.package(pkg)
rd <- find_topic(pkg, topic)
path <- file.path(pkg$path, "man", rd)
dev_example <- function(topic, strict = FALSE) {
path <- find_topic(topic)
pkg <- as.package(names(path)[[1]])

load_all(pkg)
run_one_example(topic, path, pkg, strict = strict)
Expand Down
15 changes: 14 additions & 1 deletion R/topic-index.r
@@ -1,7 +1,8 @@
# Tools for indexing package documentation by alias, and for finding
# the rd file for a given topic (alias).

find_topic <- function(pkg, topic) {
#' @return path to rd file within package
find_pkg_topic <- function(pkg, topic) {
pkg <- as.package(pkg)

# First see if a man file of that name exists
Expand All @@ -19,6 +20,18 @@ find_topic <- function(pkg, topic) {
NULL
}

# @return complete path to man file, with name giving path to package.
find_topic <- function(topic) {
pkgs <- dev_packages()
for (pkg in pkgs) {
path <- getNamespaceInfo(pkg, "path")
rd <- find_pkg_topic(path, topic)
if (!is.null(rd)) return(setNames(file.path(path, "man", rd), path))
}

NULL
}

topic_indices <- new.env(parent = emptyenv())
topic_index <- function(pkg) {
pkg <- as.package(pkg)
Expand Down

0 comments on commit e5caa8d

Please sign in to comment.