Skip to content

Commit

Permalink
Executed styler against package source
Browse files Browse the repository at this point in the history
Fixes r-lib#1851
Added 'styler' to package 'Suggests'
  • Loading branch information
Scott Russell committed Sep 6, 2018
1 parent 8396cbf commit fc6b3ca
Show file tree
Hide file tree
Showing 67 changed files with 890 additions and 644 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Suggests:
rversions,
sessioninfo,
spelling (>= 1.1),
styler,
testthat (>= 1.0.2),
whisker
VignetteBuilder: knitr
Expand Down
18 changes: 12 additions & 6 deletions R/build-readme.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ build_readme <- function(path = ".", quiet = TRUE, ...) {

pkg <- as.package(path)

readme_path <- grep(ignore.case = TRUE, value = TRUE,
"readme[.]rmd",
list.files(c(pkg$path, file.path(pkg$path, "inst"),
full.names = TRUE)))
if (length(readme_path) == 0) { return(invisible()) }
readme_path <- grep(
ignore.case = TRUE, value = TRUE,
"readme[.]rmd",
list.files(c(pkg$path, file.path(pkg$path, "inst"),
full.names = TRUE
))
)
if (length(readme_path) == 0) {
return(invisible())
}

readme_path <- file.path(pkg$path, readme_path[[1]])

Expand All @@ -35,7 +40,8 @@ build_readme <- function(path = ".", quiet = TRUE, ...) {

output <- callr::r(build,
args = list(pkg_path = pkg$path, readme_path = readme_path, ... = ..., quiet = quiet),
show = TRUE, spinner = FALSE)
show = TRUE, spinner = FALSE
)

invisible(TRUE)
}
3 changes: 2 additions & 1 deletion R/build-site.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ build_site <- function(path = ".", quiet = TRUE, ...) {
withr::with_temp_libpaths(action = "prefix", code = {
install(pkg = pkg$path, upgrade_dependencies = FALSE, reload = FALSE, quiet = quiet)
if (isTRUE(quiet)) {
withr::with_output_sink(tempfile(),
withr::with_output_sink(
tempfile(),
pkgdown::build_site(pkg = pkg$path, ...)
)
} else {
Expand Down
14 changes: 9 additions & 5 deletions R/check-devtools.r
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ check_version <- function(pkg = ".") {
pkg <- as.package(pkg)
ver <- unlist(numeric_version(pkg$version))

check_status(length(ver) == 3,
check_status(
length(ver) == 3,
"version number has three components",
paste0("version (", pkg$version, ") should have exactly three components")
)
Expand Down Expand Up @@ -83,8 +84,9 @@ check_news_md <- function(pkg) {
pkg <- as.package(pkg)

news_path <- file.path(pkg$path, "NEWS.md")
if (!file.exists(news_path))
if (!file.exists(news_path)) {
return()
}

ignore_path <- file.path(pkg$path, ".Rbuildignore")
if (!file.exists(ignore_path)) {
Expand All @@ -94,9 +96,10 @@ check_news_md <- function(pkg) {
}

has_news <- grepl("NEWS\\.md", ignore_lines, fixed = TRUE) |
grepl("NEWS.md", ignore_lines, fixed = TRUE)
grepl("NEWS.md", ignore_lines, fixed = TRUE)

check_status(!any(has_news),
check_status(
!any(has_news),
"NEWS.md is not ignored",
"NEWS.md now supported by CRAN and doesn't need to be ignored."
)
Expand All @@ -110,7 +113,8 @@ check_news_md <- function(pkg) {
}

check_remotes <- function(pkg) {
check_status(!has_dev_remotes(pkg),
check_status(
!has_dev_remotes(pkg),
"DESCRIPTION doesn't have Remotes field",
"Remotes field should be removed before CRAN submission."
)
Expand Down
13 changes: 7 additions & 6 deletions R/check-results.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ parse_check_results <- function(path) {

structure(
list(
errors = pieces[grepl("... ERROR", pieces, fixed = TRUE)],
errors = pieces[grepl("... ERROR", pieces, fixed = TRUE)],
warnings = pieces[grepl("... WARN", pieces, fixed = TRUE)],
notes = pieces[grepl("... NOTE", pieces, fixed = TRUE)]
notes = pieces[grepl("... NOTE", pieces, fixed = TRUE)]
),
path = path,
class = "check_results"
Expand All @@ -23,10 +23,10 @@ signal_check_results <- function(x, on = c("none", "error", "warning", "note"))

on <- match.arg(on)
has_problem <- switch(on,
none = FALSE,
error = has$errors,
none = FALSE,
error = has$errors,
warning = has$errors | has$warnings,
note = has$errors | has$warnings | has$notes
note = has$errors | has$warnings | has$notes
)

if (has_problem) {
Expand Down Expand Up @@ -90,8 +90,9 @@ trunc_middle <- function(x, n_max = 25, n_top = 10, n_bottom = 10) {
lines <- strsplit(x, "\n", fixed = TRUE)[[1]]
nlines <- length(lines)

if (nlines <= n_max)
if (nlines <= n_max) {
return(x)
}

paste(c(
lines[1:n_top],
Expand Down
25 changes: 15 additions & 10 deletions R/check-win.r
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ check_win_oldrelease <- function(pkg = ".", args = NULL, quiet = FALSE, ...) {

check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelease"),
args = NULL, quiet = FALSE, ...) {

pkg <- as.package(pkg)
version <- match.arg(version, several.ok = TRUE)

if (!quiet) {
message("Building windows version of ", pkg$package, " (", pkg$version, ")",
" for ", paste(version, collapse = ", "),
" with win-builder.r-project.org.\n")
message(
"Building windows version of ", pkg$package, " (", pkg$version, ")",
" for ", paste(version, collapse = ", "),
" with win-builder.r-project.org.\n"
)
if (interactive() && yesno("Email results to ", maintainer(pkg)$email, "?")) {
return(invisible())
}
Expand All @@ -59,15 +60,19 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea
built_path <- pkgbuild::build(pkg$path, tempdir(), args = args, quiet = quiet, ...)
on.exit(unlink(built_path))

url <- paste0("ftp://win-builder.r-project.org/", version, "/",
basename(built_path))
url <- paste0(
"ftp://win-builder.r-project.org/", version, "/",
basename(built_path)
)
lapply(url, upload_ftp, file = built_path)

if (!quiet) {
message("[", strftime(Sys.time(), "%I:%M %p (%Y-%m-%d)"), "] ",
"Check ", maintainer(pkg)$email, " for a link to the built package",
if (length(version) > 1) "s" else "",
" in 15-30 mins.")
message(
"[", strftime(Sys.time(), "%I:%M %p (%Y-%m-%d)"), "] ",
"Check ", maintainer(pkg)$email, " for a link to the built package",
if (length(version) > 1) "s" else "",
" in 15-30 mins."
)
}

invisible()
Expand Down
4 changes: 1 addition & 3 deletions R/check.r
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ check <- function(pkg = ".",
check_dir = tempdir(),
cleanup = TRUE,
error_on = c("never", "error", "warning", "note")) {

pkg <- as.package(pkg)
withr::local_options(list(warn = 1))

Expand Down Expand Up @@ -156,9 +155,8 @@ check <- function(pkg = ".",
check_built <- function(path = NULL, cran = TRUE,
remote = FALSE, incoming = remote, force_suggests = FALSE,
run_dont_test = FALSE, manual = FALSE, args = "--timings",
env_vars = NULL, check_dir = tempdir(), quiet = FALSE,
env_vars = NULL, check_dir = tempdir(), quiet = FALSE,
error_on = c("never", "error", "warning", "note")) {

if (missing(error_on) && !interactive()) {
error_on <- "warning"
}
Expand Down
1 change: 0 additions & 1 deletion R/cran.r
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package_url <- function(package, repos,
# @param package The name of the package.
# @param available A matrix of information about packages.
cran_pkg_version <- function(package, available = available.packages()) {

idx <- available[, "Package"] == package
if (any(idx)) {
as.package_version(available[package, "Version"])
Expand Down
20 changes: 12 additions & 8 deletions R/create.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@ create <- function(path, description = getOption("devtools.desc"),
if (!file.exists(path)) {
if (!dir.create(path)) {
stop("Failed to create package directory '", basename(path), "'",
call. = FALSE)
call. = FALSE
)
}
}

# if the directory exists but is not empty, bail
files <- list.files(path)
if (length(files)) {

valid <- length(files) == 1 && tools::file_ext(files) == "Rproj"
if (!valid)
if (!valid) {
stop("Directory exists and is not empty", call. = FALSE)
}
}

path <- normalizePath(path, winslash = "/", mustWork = TRUE)
setup(path = path, description = description, rstudio = rstudio,
check = check, quiet = quiet)
setup(
path = path, description = description, rstudio = rstudio,
check = check, quiet = quiet
)

invisible(TRUE)
}
Expand Down Expand Up @@ -71,7 +74,8 @@ create_description <- function(path = ".", extra = getOption("devtools.desc"),
subdir <- file.path(path, c("R", "src", "data"))
if (!any(file.exists(subdir))) {
stop("'", path, "' does not look like a package: no R/, src/ or data directories",
call. = FALSE)
call. = FALSE
)
}

desc <- build_description(extract_package_name(path), extra)
Expand All @@ -95,7 +99,7 @@ build_description <- function(name, extra = list()) {
Version = "0.0.0.9000",
"Authors@R" = getOption("devtools.desc.author"),
Description = "What the package does (one paragraph).",
Depends = paste0("R (>= ", as.character(getRversion()) ,")"),
Depends = paste0("R (>= ", as.character(getRversion()), ")"),
License = getOption("devtools.desc.license"),
Suggests = getOption("devtools.desc.suggests"),
Encoding = "UTF-8",
Expand Down Expand Up @@ -137,7 +141,7 @@ create_namespace <- function(path) {
if (file.exists(ns_path)) return()

cat(
'# Generated by roxygen2: fake comment so roxygen2 overwrites silently.\n',
"# Generated by roxygen2: fake comment so roxygen2 overwrites silently.\n",
'exportPattern("^[^\\\\.]")\n',
sep = "",
file = ns_path
Expand Down
12 changes: 5 additions & 7 deletions R/decompress.r
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ source_pkg <- function(path, subdir = NULL, before_install = NULL) {
}

# Call before_install for bundles (if provided)
if (!is.null(info$bundle) && !is.null(before_install))
if (!is.null(info$bundle) && !is.null(before_install)) {
before_install(info$bundle, info$pkg_path)
}

info$pkg_path
}
Expand All @@ -50,23 +51,20 @@ decompress <- function(src, target) {
if (grepl("\\.zip$", src)) {
my_unzip(src, target)
outdir <- getrootdir(as.vector(utils::unzip(src, list = TRUE)$Name))

} else if (grepl("\\.tar$", src)) {
utils::untar(src, exdir = target)
outdir <- getrootdir(utils::untar(src, list = TRUE))

} else if (grepl("\\.(tar\\.gz|tgz)$", src)) {
utils::untar(src, exdir = target, compressed = "gzip")
outdir <- getrootdir(utils::untar(src, compressed = "gzip", list = TRUE))

} else if (grepl("\\.(tar\\.bz2|tbz)$", src)) {
utils::untar(src, exdir = target, compressed = "bzip2")
outdir <- getrootdir(utils::untar(src, compressed = "bzip2", list = TRUE))

} else {
ext <- gsub("^[^.]*\\.", "", src)
stop("Don't know how to decompress files with extension ", ext,
call. = FALSE)
call. = FALSE
)
}

file.path(target, outdir)
Expand All @@ -76,7 +74,7 @@ decompress <- function(src, target) {
# Returns everything before the last slash in a filename
# getdir("path/to/file") returns "path/to"
# getdir("path/to/dir/") returns "path/to/dir"
getdir <- function(path) sub("/[^/]*$", "", path)
getdir <- function(path) sub("/[^/]*$", "", path)

# Given a list of files, returns the root (the topmost folder)
# getrootdir(c("path/to/file", "path/to/other/thing")) returns "path/to"
Expand Down
Loading

0 comments on commit fc6b3ca

Please sign in to comment.