Skip to content

Commit

Permalink
Hadley-fication
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Aug 12, 2012
1 parent 0fc4ad7 commit d77b9dd
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 88 deletions.
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Imports:
utils,
tools,
memoise,
brew
whisker

This comment has been minimized.

Copy link
@yoni

yoni Aug 14, 2012

Contributor

Nice. I didn't know this package existed. I like keeping logic out of my templates. :)

Suggests:
testthat,
roxygen2,
Expand Down Expand Up @@ -64,5 +64,3 @@ Collate:
'inst.r'
'metadata.r'
'create.r'
'create-package-doc.r'
'save-package-description.R'
4 changes: 1 addition & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export(check_doc)
export(check)
export(clean_source)
export(clean_vignettes)
export(create_package_doc)
export(create)
export(dev_meta)
export(dev_mode)
Expand Down Expand Up @@ -41,7 +40,6 @@ export(revdep_check)
export(revdep_maintainers)
export(revdep)
export(run_examples)
export(save_package_description)
export(set_path)
export(show_news)
export(show_rd)
Expand All @@ -58,7 +56,6 @@ export(with_locale)
export(with_options)
export(with_par)
export(with_path)
importFrom(brew,brew)
importFrom(httr,config)
importFrom(httr,content)
importFrom(httr,GET)
Expand All @@ -71,3 +68,4 @@ importFrom(tools,file_ext)
importFrom(tools,package_dependencies)
importFrom(tools,Rd2txt)
importFrom(utils,install.packages)
importFrom(whisker,whisker.render)
15 changes: 0 additions & 15 deletions R/create-package-doc.r

This file was deleted.

84 changes: 49 additions & 35 deletions R/create.r
Original file line number Diff line number Diff line change
@@ -1,50 +1,64 @@
#' Creates a new package, following all devtools package conventions.
#'
#' @param name character string: the package name and directory name for
#' your package.
#' @param path to put the package directory in
#' @param description list of description values to override default values or add additional values.
#' Similar to \code{\link{package.skeleton}}, except that it only creates
#' the standard devtools directory structures, it doesn't try and create
#' source code and data files by inspecting the global environment.
#'
#' @param path location to create new package. The last component of the path

This comment has been minimized.

Copy link
@yoni

yoni Aug 14, 2012

Contributor

I think I get the rationale, but not sure I like combining the path with the package name. This way of doing it seems less explicit and less readable. But that's a matter of taste.

This comment has been minimized.

Copy link
@hadley

hadley Aug 16, 2012

Author Member

I was thinking about adding back the name parameter so you could have it either way. If not specified, it would default to basename(path). What do you think?

This comment has been minimized.

Copy link
@yoni

yoni Aug 18, 2012

Contributor

In the scenario you mentioned, there would be two ways of calling the function, with the 'path' parameter meaning something different in each case. That seems confusing and error-prone. Personally, I prefer for functions to have a single simple interface, without too many cases for folks to understand. Specifically, these patterns seem confusing:

# same result:
create(path='.', name='fancyPackage')
create(path='./fancyPackage')

# likely error:
create(path='./fancyPackage', name='fancyPackage')

I'd have both parameters required, with 'path' not including the package name.

This comment has been minimized.

Copy link
@hadley

hadley Aug 29, 2012

Author Member

I went with the parameterisation I did because it's more inline with the other devtools packages. i.e you could do:

path <- "mypath/..."
create(path)
install(path)
check(path)
#' will be used as the package name.
#' @param description list of description values to override default values or
#' add additional values.
#' @param ... other options passed to \code{package.skeleton}

This comment has been minimized.

Copy link
@yoni

yoni Aug 14, 2012

Contributor

This parameter is not being used.

This comment has been minimized.

Copy link
@hadley

hadley Aug 16, 2012

Author Member

Fixed - thanks.

#' @seealso Text with \code{\link{package.skeleton}}
#' @export
#' @examples
#'
#' # Create a package using all defaults:
#' path_to_package <- tempdir()
#' create(name='myDefaultPackage', path=path_to_package)
#' path <- file.path(tempdir(), "myDefaultPackage")
#' create(path)
#'
#' # Override a description attribute.
#' # Note that overriding one atribute implies that you must override
#' # all default attributes, as well.
#' my_description <- list("Maintainer"="'Yoni Ben-Meshulam' <yoni@@opower.com>")
#' create(name='myCustomPackage', path=path_to_package, description=my_description)
create <- function(
name,
path,
description=list()
) {
#' path <- file.path(tempdir(), "myCustomPackage")
#' my_description <- list("Maintainer" =
#' "'Yoni Ben-Meshulam' <yoni@@opower.com>")
#' create("../myCustomPackage", my_description)
create <- function(path, description = list()) {
name <- basename(path)
message("Creating package ", name, " in ", dirname(path))

description.defaults <- list(
Package=name,
Maintainer="Who to complain to <yourfault@somewhere.net>",
Author=Sys.getenv("USER"),
Version="1.0",
License="GPL-3",
Title=name,
Description=name,
Suggests="\ntestthat,\nroxygen2"
)
if (file.exists(path)) {
stop("Directory already exists", call. = FALSE)
}
if (!file.exists(dirname(path))) {
stop("Parent directory does not exist.", call. = FALSE)
}

package_path <- file.path(path, name)
message(sprintf("Creating package [%s] in path [%s]", name, package_path))
dir.create(path)

dir.create(package_path)
dir.create(file.path(package_path, 'R'))
defaults <- list(

This comment has been minimized.

Copy link
@yoni

yoni Aug 14, 2012

Contributor

Do you have this style codified someplace I can access it? I've been using R-Vim plugin, which aligns parens differently. Would love to switch to this style when working on devtools, but I don't want to reinvent the wheel.

This comment has been minimized.

Copy link
@hadley

This comment has been minimized.

Copy link
@yoni

yoni Aug 18, 2012

Contributor

Right, I've read that. What I meant was do you have an automated way of enforcing it in your editor? I use vim with the vim R plugin, which enforces a somewhat different style.

Anyhow, I guess I'll just have to codify it manually in my vim settings.

Package = name,
Maintainer = "Who to complain to <yourfault@somewhere.net>",
Author = Sys.getenv("USER"),
Version = "1.0",
License = "GPL-3",
Title = "",
Description = "",
Suggests = "\ntestthat,\nroxygen2"
)
description <- modifyList(defaults, description)
write.dcf(description, file.path(path, 'DESCRIPTION'))

dir.create(file.path(path, "R"))
create_package_doc(path, name)

description <- modifyList(description.defaults, description)

save_package_description(package_path, description)
create_package_doc(package_path, name)
check(path)
}

check(package_path)
#' @importFrom whisker whisker.render
create_package_doc <- function(path, name) {
template <- readLines(system.file("templates", "packagename-package.r",
package = "devtools"))
out <- whisker.render(template, list(name = name))

target <- file.path(path, "R", paste(name, "-package.r", sep = ""))
writeLines(out, target)
}
13 changes: 0 additions & 13 deletions R/save-package-description.R

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Building and installing:
arbitrary url. `install_version` installs a specified version from cran,

Creating a new package:
* `create("pkg")` creates a new R package, followint all devtools conventions.

* `create("path/to/pkg")` creates a new R package following devtools
conventions. called `pkg` in `path/to`,

Check and release:

Expand Down
7 changes: 2 additions & 5 deletions inst/templates/packagename-package.r
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#' <%= name %>
#' {{{ name }}}
#'
#' @name <%= name %>-package
#' @aliases <%= name %>
#' @name {{{ name }}}
#' @docType package
#' @title <%= name %>
#' @keywords package
NULL
29 changes: 16 additions & 13 deletions man/create.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@
\alias{create}
\title{Creates a new package, following all devtools package conventions.}
\usage{
create(name, path, description = list())
create(path, description = list())
}
\arguments{
\item{name}{character string: the package name and
directory name for your package.}

\item{path}{to put the package directory in}
\item{path}{location to create new package. The last
component of the path will be used as the package name.}

\item{description}{list of description values to override
default values or add additional values.}

\item{...}{other options passed to
\code{package.skeleton}}
}
\description{
Creates a new package, following all devtools package
conventions.
Similar to \code{\link{package.skeleton}}, except that it
only creates the standard devtools directory structures,
it doesn't try and create source code and data files by
inspecting the global environment.
}
\examples{
# Create a package using all defaults:
path_to_package <- tempdir()
create(name='myDefaultPackage', path=path_to_package)
path <- file.path(tempdir(), "myDefaultPackage")
create(path)
# Override a description attribute.
# Note that overriding one atribute implies that you must override
# all default attributes, as well.
my_description <- list("Maintainer"="'Yoni Ben-Meshulam' <yoni@opower.com>")
create(name='myCustomPackage', path=path_to_package, description=my_description)
path <- file.path(tempdir(), "myCustomPackage")
my_description <- list("Maintainer" =
"'Yoni Ben-Meshulam' <yoni@opower.com>")
create("../myCustomPackage", my_description)
}
\seealso{
Text with \code{\link{package.skeleton}}
Expand Down

0 comments on commit d77b9dd

Please sign in to comment.