Skip to content

Commit

Permalink
Update use_build_ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored and krlmlr committed Nov 9, 2016
1 parent a5e5805 commit 0da5710
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 32 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 5.0.1
Suggests: testthat
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# usethis 0.0.0.9000

* Removed old `add_build_ignore()`
32 changes: 13 additions & 19 deletions R/ignore.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
#' Add a file to \code{.Rbuildignore}
#' Add files to \code{.Rbuildignore}
#'
#' \code{.Rbuildignore} has a regular expression on each line, but it's
#' usually easier to work with specific file names. By default, will (crudely)
#' turn a filename into a regular expression that will only match that
#' path. Repeated entries will be silently removed.
#' usually easier to work with specific file names. By default,
#' \code{use_build_ignore} will (crudely) turn a filename into a regular
#' expression that will only match that path. Repeated entries will be
#' silently removed.
#'
#' @param pkg package description, can be path or package name. See
#' \code{\link{as.package}} for more information
#' @param files Name of file.
#' @param base_path Base path to package root.
#' @param files Character vector of path naems.
#' @param escape If \code{TRUE}, the default, will escape \code{.} to
#' \code{\\.} and surround with \code{^} and \code{$}.
#' @return Nothing, called for its side effect.
#' @export
#' @aliases add_build_ignore
#' @family infrastructure
#' @keywords internal
use_build_ignore <- function(files, escape = TRUE, pkg = ".") {
pkg <- as.package(pkg)

use_build_ignore <- function(files, escape = TRUE, base_path = ".") {
if (escape) {
files <- paste0("^", gsub("\\.", "\\\\.", files), "$")
files <- escape_path(files)
}

path <- file.path(pkg$path, ".Rbuildignore")
path <- file.path(base_path, ".Rbuildignore")
union_write(path, files)

invisible(TRUE)
}


add_build_ignore <- function(pkg = ".", files, escape = TRUE) {
use_build_ignore(files, escape = escape, pkg = pkg)
escape_path <- function(x) {
x <- gsub("\\.", "\\\\.", x)
paste0("^", x, "$")
}



2 changes: 1 addition & 1 deletion R/templates.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use_template <- function(template, save_as = template, data = list(),
ignore = FALSE, open = FALSE, pkg = ".") {
ignore = FALSE, open = FALSE, base_path = ".") {
pkg <- as.package(pkg)

path <- file.path(pkg$path, save_as)
Expand Down
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

union_write <- function(path, new_lines) {
stopifnot(is.character(new_lines))

if (file.exists(path)) {
lines <- readLines(path, warn = FALSE)
} else {
Expand Down
19 changes: 8 additions & 11 deletions man/use_build_ignore.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(usethis)

test_check("usethis")
5 changes: 5 additions & 0 deletions tests/testthat/test-use_build_ignore.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
context("use_build_ignore")

test_that(". escaped around surround by anchors", {
expect_equal(escape_path("."), "^\\.$")
})

0 comments on commit 0da5710

Please sign in to comment.