Skip to content

Commit 06e3e22

Browse files
committed
Merge branch 'r-0.1' into production
2 parents c13c2ac + 1efd1a1 commit 06e3e22

File tree

6 files changed

+61
-48
lines changed

6 files changed

+61
-48
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
^scripts/deploy-pages\.sh$
99
^_pkgdown\.yml$
1010
^tic\.R$
11+
^cran-comments\.md$
12+
^docs$

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.Rproj.user
22
.Rhistory
33
.RData
4+
/docs

DESCRIPTION

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
Package: here
22
Title: A Simpler Way to Find Your Files
3-
Version: 0.0-6
3+
Version: 0.1
44
Authors@R: person("Kirill", "Müller", role = c("aut", "cre"), email = "krlmlr+r@mailbox.org")
55
Description: Constructs paths to your project's files.
6+
The 'here()' function uses a reasonable heuristics to find your project's
7+
files, based on the current working directory at the time when the package
8+
is loaded. Use it as a drop-in replacement for 'file.path()', it will always
9+
locate the files relative to your project root.
610
Imports: rprojroot (>= 1.2)
711
License: GPL-3
812
Encoding: UTF-8
913
LazyData: true
10-
Date: 2017-01-16
14+
Date: 2017-05-27
1115
URL: https://github.com/krlmlr/here, http://krlmlr.github.io/here
1216
BugReports: https://github.com/krlmlr/here/issues
1317
Roxygen: list(markdown = TRUE)
14-
RoxygenNote: 5.0.1.9000
15-
Remotes: krlmlr/rprojroot@r-1.2
18+
RoxygenNote: 6.0.1

NEWS.md

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
1-
## here 0.0-6 (2017-01-16)
1+
# here 0.1 (2017-01-25)
22

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

8-
9-
## here 0.0-5 (2016-10-29)
10-
11-
- `remake` projects are also recognized by default.
12-
- Silently falling back to current working directory if no root found.
13-
14-
15-
## here 0.0-4 (2016-10-29)
16-
17-
- `pkgdown`.
18-
19-
20-
## here 0.0-3 (2016-07-19)
21-
22-
- Install `rprojroot` from GitHub.
23-
- Show message only when attaching.
24-
25-
26-
## here 0.0-2 (2016-07-19)
27-
28-
- Better argument documentation.
29-
- README.
30-
31-
32-
## here 0.0-1 (2016-07-19)
33-
34-
- A single function `here()`
35-
- Uses a fixed root that can be either an RStudio project, or an R package
36-
- The root is established at package loading time, and shown with a message
5+
- Main function `here()`
6+
- 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.
7+
- The root is established at package loading time, and shown with a message.
8+
- The current working directory is used as a fallback.
9+
- The `set_here()` function creates a `.here` file so that a directory is recognized as root by `here()`.
10+
- The `dr_here()` function explains the reasoning of `here()` for the current session.

R/here.R

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#' the \pkg{rprojroot} package for more control,
1111
#' or for package development.
1212
#'
13-
#' @evalRd format_root_section()
13+
#' @evalRd roxygen2:::full_markdown(format_root_section())
1414
#'
15-
#' @param ... \code{[character]}\cr
15+
#' @param ... `[character]`\cr
1616
#' Path components below the project root, can be empty.
1717
#' @export
1818
#' @examples
@@ -26,31 +26,41 @@ here <- function(...) {
2626
#' @description `dr_here()` shows a message that by default also includes the
2727
#' reason why `here()` is set to a particular directory. Use this function
2828
#' if `here()` gives unexpected results.
29-
#' @param show_reason \code{[logical(1)]}\cr
29+
#' @param show_reason `[logical(1)]`\cr
3030
#' Include reason in output of `dr_here()`, defaults to `TRUE`.
3131
#' @export
3232
dr_here <- function(show_reason = TRUE) {
3333
message(format_dr_here(show_reason = show_reason))
3434
}
3535

3636
format_dr_here <- function(show_reason) {
37-
root <- .root_env$f()
3837
paste0(
39-
"here() starts at ", root,
38+
"here() starts at ", .root_env$f(),
4039
if (show_reason) {
41-
paste0(", because it ", get_root_desc(.root_env$crit, root))
40+
paste0(", because ", format_reason())
4241
}
4342
)
4443
}
4544

45+
format_reason <- function() {
46+
root <- .root_env$f()
47+
if (any(vapply(.root_env$crit$testfun, function(f) f(root), logical(1L)))) {
48+
paste0("it ", get_root_desc(.root_env$crit, .root_env$f()))
49+
} else {
50+
paste0("none of the following criteria apply for this directory or any of its parents:\n",
51+
format_root_criteria_items(), "\n",
52+
"Use set_here() to create a `.here` file")
53+
}
54+
}
55+
4656
#' @rdname here
4757
#' @description `set_here()` creates an empty file named `.here`, by default
4858
#' in the current directory. When `here` encounters such a file, it uses the
4959
#' directory that contains this file as root. This is useful if none of the
5060
#' default criteria apply.
51-
#' @param path \code{[character(1)]}\cr
61+
#' @param path `[character(1)]`\cr
5262
#' Directory where to create `.here` file, defaults to the current directory.
53-
#' @param verbose \code{[logical(1)]}\cr
63+
#' @param verbose `[logical(1)]`\cr
5464
#' Verbose output, defaults to `TRUE`.
5565
#' @export
5666
set_here <- function(path = ".", verbose = TRUE) {
@@ -78,7 +88,12 @@ is_here <- has_file(".here")
7888
#' @import rprojroot
7989
.onLoad <- function(libname, pkgname) {
8090
.root_env$crit <- is_here | is_rstudio_project | is_r_package | is_remake_project | is_projectile_project | is_vcs_root
81-
.root_env$f <- .root_env$crit$make_fix_file()
91+
tryCatch(
92+
.root_env$f <- .root_env$crit$make_fix_file(),
93+
error = function(e) {
94+
.root_env$f <- from_wd$make_fix_file()
95+
}
96+
)
8297
}
8398

8499
.onAttach <- function(libname, pkgname) {
@@ -89,10 +104,14 @@ format_root_section <- function() {
89104
paste(
90105
"\\section{Project root}{",
91106
"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:",
92-
paste(format(.root_env$crit)[-1], collapse = "\n"),
107+
format_root_criteria_items(),
93108
"",
94109
"Once established, the root directory doesn't change during the active R session. `here()` then appends the arguments to the root directory.",
95110
"}",
96111
sep = "\n"
97112
)
98113
}
114+
115+
format_root_criteria_items <- function() {
116+
paste(format(.root_env$crit)[-1L], collapse = "\n")
117+
}

cran-comments.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Test environments
2+
* local Ubuntu 16.10 install, R 3.4.0
3+
* ubuntu 12.04 (on travis-ci), R release, devel, and oldrel
4+
* win-builder (devel and release)
5+
6+
## R CMD check results
7+
8+
0 errors | 0 warnings | 1 note
9+
10+
* This is a new release.
11+
12+
## Reverse dependencies
13+
14+
This is a new release, so there are no reverse dependencies.

0 commit comments

Comments
 (0)