Skip to content

Commit

Permalink
Merge branch 'r-0.1' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed May 29, 2017
2 parents c13c2ac + 1efd1a1 commit 06e3e22
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
^scripts/deploy-pages\.sh$
^_pkgdown\.yml$
^tic\.R$
^cran-comments\.md$
^docs$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.Rproj.user
.Rhistory
.RData
/docs
11 changes: 7 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
Package: here
Title: A Simpler Way to Find Your Files
Version: 0.0-6
Version: 0.1
Authors@R: person("Kirill", "Müller", role = c("aut", "cre"), email = "[email protected]")
Description: Constructs paths to your project's files.
The 'here()' function uses a reasonable heuristics to find your project's
files, based on the current working directory at the time when the package
is loaded. Use it as a drop-in replacement for 'file.path()', it will always
locate the files relative to your project root.
Imports: rprojroot (>= 1.2)
License: GPL-3
Encoding: UTF-8
LazyData: true
Date: 2017-01-16
Date: 2017-05-27
URL: https://github.com/krlmlr/here, http://krlmlr.github.io/here
BugReports: https://github.com/krlmlr/here/issues
Roxygen: list(markdown = TRUE)
RoxygenNote: 5.0.1.9000
Remotes: krlmlr/[email protected]
RoxygenNote: 6.0.1
42 changes: 8 additions & 34 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
## here 0.0-6 (2017-01-16)
# here 0.1 (2017-01-25)

- New `set_here()` function that creates a `.here` file and talks about it by default (#1).
- New `dr_here()`, describes why `here()` has settled for a particular path.
- Recognize projectile projects and VCS roots.
- Using working directory as fallback produces wrong results, reverted.
Initial CRAN release.


## here 0.0-5 (2016-10-29)

- `remake` projects are also recognized by default.
- Silently falling back to current working directory if no root found.


## here 0.0-4 (2016-10-29)

- `pkgdown`.


## here 0.0-3 (2016-07-19)

- Install `rprojroot` from GitHub.
- Show message only when attaching.


## here 0.0-2 (2016-07-19)

- Better argument documentation.
- README.


## here 0.0-1 (2016-07-19)

- A single function `here()`
- Uses a fixed root that can be either an RStudio project, or an R package
- The root is established at package loading time, and shown with a message
- Main function `here()`
- Uses a fixed root that contains a `.here` file or can be either an RStudio project, an R package, a `remake` project, a Projectile project, or a VCS repository.
- The root is established at package loading time, and shown with a message.
- The current working directory is used as a fallback.
- The `set_here()` function creates a `.here` file so that a directory is recognized as root by `here()`.
- The `dr_here()` function explains the reasoning of `here()` for the current session.
39 changes: 29 additions & 10 deletions R/here.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#' the \pkg{rprojroot} package for more control,
#' or for package development.
#'
#' @evalRd format_root_section()
#' @evalRd roxygen2:::full_markdown(format_root_section())
#'
#' @param ... \code{[character]}\cr
#' @param ... `[character]`\cr
#' Path components below the project root, can be empty.
#' @export
#' @examples
Expand All @@ -26,31 +26,41 @@ here <- function(...) {
#' @description `dr_here()` shows a message that by default also includes the
#' reason why `here()` is set to a particular directory. Use this function
#' if `here()` gives unexpected results.
#' @param show_reason \code{[logical(1)]}\cr
#' @param show_reason `[logical(1)]`\cr
#' Include reason in output of `dr_here()`, defaults to `TRUE`.
#' @export
dr_here <- function(show_reason = TRUE) {
message(format_dr_here(show_reason = show_reason))
}

format_dr_here <- function(show_reason) {
root <- .root_env$f()
paste0(
"here() starts at ", root,
"here() starts at ", .root_env$f(),
if (show_reason) {
paste0(", because it ", get_root_desc(.root_env$crit, root))
paste0(", because ", format_reason())
}
)
}

format_reason <- function() {
root <- .root_env$f()
if (any(vapply(.root_env$crit$testfun, function(f) f(root), logical(1L)))) {
paste0("it ", get_root_desc(.root_env$crit, .root_env$f()))
} else {
paste0("none of the following criteria apply for this directory or any of its parents:\n",
format_root_criteria_items(), "\n",
"Use set_here() to create a `.here` file")
}
}

#' @rdname here
#' @description `set_here()` creates an empty file named `.here`, by default
#' in the current directory. When `here` encounters such a file, it uses the
#' directory that contains this file as root. This is useful if none of the
#' default criteria apply.
#' @param path \code{[character(1)]}\cr
#' @param path `[character(1)]`\cr
#' Directory where to create `.here` file, defaults to the current directory.
#' @param verbose \code{[logical(1)]}\cr
#' @param verbose `[logical(1)]`\cr
#' Verbose output, defaults to `TRUE`.
#' @export
set_here <- function(path = ".", verbose = TRUE) {
Expand Down Expand Up @@ -78,7 +88,12 @@ is_here <- has_file(".here")
#' @import rprojroot
.onLoad <- function(libname, pkgname) {
.root_env$crit <- is_here | is_rstudio_project | is_r_package | is_remake_project | is_projectile_project | is_vcs_root
.root_env$f <- .root_env$crit$make_fix_file()
tryCatch(
.root_env$f <- .root_env$crit$make_fix_file(),
error = function(e) {
.root_env$f <- from_wd$make_fix_file()
}
)
}

.onAttach <- function(libname, pkgname) {
Expand All @@ -89,10 +104,14 @@ format_root_section <- function() {
paste(
"\\section{Project root}{",
"Starting with the current working directory during package load time, `here` will walk the directory hierarchy upwards until it finds a directory that satisfies at least one of the following conditions:",
paste(format(.root_env$crit)[-1], collapse = "\n"),
format_root_criteria_items(),
"",
"Once established, the root directory doesn't change during the active R session. `here()` then appends the arguments to the root directory.",
"}",
sep = "\n"
)
}

format_root_criteria_items <- function() {
paste(format(.root_env$crit)[-1L], collapse = "\n")
}
14 changes: 14 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Test environments
* local Ubuntu 16.10 install, R 3.4.0
* ubuntu 12.04 (on travis-ci), R release, devel, and oldrel
* win-builder (devel and release)

## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.

## Reverse dependencies

This is a new release, so there are no reverse dependencies.

0 comments on commit 06e3e22

Please sign in to comment.