-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use file.path instead of paste0 in cache_rds #70
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I was intentionally using paste0()
here mainly because I was considering the case of using this function inside knitr code chunks. The chunk option cache.path
is not necessarily a dir but just a path prefix.
I totally understand that file.path()
would make more sense without considering this special case, and just suggested two changes that would make the special case still work. Do they make sense to you?
BTW, xfun::mark_dirs()
can add the trailing slash to dirs (but only if a dir exists).
@@ -112,7 +112,7 @@ cache_rds = function( | |||
if (missing(dir) && !is.null(d <- knitr::opts_current$get('cache.path'))) | |||
dir = d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dir = d | |
dir = I(d) |
@@ -112,7 +112,7 @@ cache_rds = function( | |||
if (missing(dir) && !is.null(d <- knitr::opts_current$get('cache.path'))) | |||
dir = d | |||
} | |||
path = paste0(dir, file) | |||
path = file.path(dir, file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path = file.path(dir, file) | |
path = (if (inherits(dir, 'AsIs')) paste0 else file.path)(dir, file) |
Also the example is failing on Windows: https://github.com/yihui/xfun/actions/runs/3215127507/jobs/5256006471 |
7d2ac85
to
1ba376e
Compare
Very simple change, so that is not necessary to pass a trailing slash (
/
) to thedir
argument ofcache_rds
. This is specially useful when the usingfile.path()
itself for thedir
argument, such as:Maybe it is a better practice to always use a trailing slash for folders and no slash for files, but it is not always practical. The output of
here::here()
, for example, doesn't differ between folder and files in this way.Please let me know if I am doing something wrong, or just disregard the PR. Thank you for these great miscellaneous functions :)