yihui / xfun

Miscellaneous R functions
https://yihui.org/xfun/
Other
141 stars 28 forks source link

use file.path instead of paste0 in cache_rds #70

Open avila opened 2 years ago

avila commented 2 years ago

Very simple change, so that is not necessary to pass a trailing slash (/) to the dir argument of cache_rds. This is specially useful when the using file.path() itself for the dir argument, such as:

path <- list(checkpoints = file.path("checkpoints"))

long_calcs <- cache_rds(
  expr = {
    Sys.sleep(10)
  },
  dir = file.path(path$checkpoints)
)

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 :)

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

yihui commented 2 years ago

Also the example is failing on Windows: https://github.com/yihui/xfun/actions/runs/3215127507/jobs/5256006471