Skip to content

Commit 1cded78

Browse files
committed
Provide helpers for base R home definitions
1 parent 4157296 commit 1cded78

File tree

5 files changed

+61
-34
lines changed

5 files changed

+61
-34
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ export(path_abs)
7070
export(path_common)
7171
export(path_dir)
7272
export(path_expand)
73+
export(path_expand_r)
7374
export(path_ext)
7475
export(path_ext_remove)
7576
export(path_ext_set)
7677
export(path_file)
7778
export(path_filter)
7879
export(path_home)
80+
export(path_home_r)
7981
export(path_join)
8082
export(path_norm)
8183
export(path_real)

NEWS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# fs 1.1.0.9000
1+
# fs 1.2.0
22

33
## Breaking changes
44

@@ -8,7 +8,7 @@
88
definitions from other programming environments such as python and rust. This
99
is also more compatible with external tools such as git and ssh, both of
1010
which put user-level files in `USERPROFILE` by default. To mimic R's (and
11-
previous) behavior use `Sys.setenv("R_FS_HOME" = Sys.getenv("R_USER"))`
11+
previous) behavior there are functions `path_expand_r()` and `path_home_r()`.
1212

1313
* Handling missing values are more consistent. In general `is_*` functions
1414
always return `FALSE` for missing values, `path_*` functions always propagate
@@ -22,7 +22,7 @@
2222
## Bugfixes
2323

2424
* Fix home expansion on systems without readline (#60).
25-
* Fix propagation of NA values in path_norm (#63).
25+
* Fix propagation of NA values in `path_norm()` (#63).
2626

2727
## Features
2828

R/path.R

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ path_rel <- function(path, start = ".") {
220220
#' * `path_home()` constructs a path within the expanded users home directory,
221221
#' calling it with _no_ arguments can be useful to verify what fs considers the
222222
#' home directory.
223+
#' * `path_expand_r()` and `path_home_r()` are equivalents which always use R's
224+
#' definition of the home directory.
223225
#' @details
224226
#' `path_expand()` Differs from [path.expand()] in the interpretation of the
225227
#' home directory of Windows. In particular `path_expand()` uses the path set
@@ -248,26 +250,41 @@ path_rel <- function(path, start = ".") {
248250
#' @inheritParams path_math
249251
#' @export
250252
#' @examples
251-
#' # Make fs home equivalent to R definition of home
252-
#' \dontrun{
253-
#' Sys.setenv("R_FS_HOME" = Sys.getenv("R_USER"))
254-
#' path_expand("~")
255-
#' }
253+
#' # You can use `path_home()` without arguments to see what is being used as
254+
#' the home diretory.
256255
#' path_home()
257256
#' path_home("R")
257+
#'
258+
#' # This will likely differ from the above on Windows
259+
#' path_home_r()
258260
path_expand <- function(path) {
259261
path <- enc2utf8(path)
260262

261263
# We use the windows implementation if R_FS_HOME is set or if on windows
262264
path_tidy(expand_(path, Sys.getenv("R_FS_HOME") != "" || is_windows()))
263265
}
264266

267+
#' @rdname path_expand
268+
#' @export
269+
path_expand_r <- function(path) {
270+
path <- enc2utf8(path)
271+
272+
# Unconditionally use R_ExpandFileName
273+
path_tidy(expand_(path, FALSE))
274+
}
275+
265276
#' @rdname path_expand
266277
#' @export
267278
path_home <- function(...) {
268279
path(path_expand("~/"), ...)
269280
}
270281

282+
#' @rdname path_expand
283+
#' @export
284+
path_home_r <- function(...) {
285+
path(path_expand_r("~/"), ...)
286+
}
287+
271288
#' Manipulate file paths
272289
#'
273290
#' `path_file()` returns the filename portion of the path, `path_dir()` returns

fs.Rproj

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
Version: 1.0
2-
3-
RestoreWorkspace: No
4-
SaveWorkspace: No
5-
AlwaysSaveHistory: Default
6-
7-
EnableCodeIndexing: Yes
8-
UseSpacesForTab: Yes
9-
NumSpacesForTab: 2
10-
Encoding: UTF-8
11-
12-
RnwWeave: knitr
13-
LaTeX: XeLaTeX
14-
15-
AutoAppendNewline: Yes
16-
StripTrailingWhitespace: Yes
17-
18-
BuildType: Package
19-
PackageUseDevtools: Yes
20-
PackageInstallArgs: --no-multiarch --with-keep.source
21-
PackageRoxygenize: rd,collate,namespace
1+
Version: 1.0
2+
3+
RestoreWorkspace: No
4+
SaveWorkspace: No
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: knitr
13+
LaTeX: XeLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
17+
18+
BuildType: Package
19+
PackageUseDevtools: Yes
20+
PackageInstallArgs: --no-multiarch --with-keep.source
21+
PackageRoxygenize: rd,collate,namespace

man/path_expand.Rd

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)