here::here() vs. fs::path_wd()

,

Hi R Studio Community,

I'm trying to figure out the difference between here::here() and fs::path_wd(), particularly scenarios where it would be safer to use one vs. the other. For example, in Rprojects vs. not within a project? From Rmarkdown? In my initial testing, they seem to work very similarly.

Which do you use and why?

Thanks for your thoughts!

library(here)
#> here() starts at /private/var/folders/w7/jvqhm46x3756vqb0x7fllts80000gn/T/RtmpHOhpew/reprex2e823b91f67b
library(fs)
library(glue)

# Build a filepath
here::here("my", "path.txt")
#> [1] "/private/var/folders/w7/jvqhm46x3756vqb0x7fllts80000gn/T/RtmpHOhpew/reprex2e823b91f67b/my/path.txt"
fs::path_wd("my", "path", ext = "txt")
#> /private/var/folders/w7/jvqhm46x3756vqb0x7fllts80000gn/T/RtmpHOhpew/reprex2e823b91f67b/my/path.txt

# Build datestamped filepath
here::here("my", glue::glue("{Sys.Date()}_path.txt"))
#> [1] "/private/var/folders/w7/jvqhm46x3756vqb0x7fllts80000gn/T/RtmpHOhpew/reprex2e823b91f67b/my/2021-02-16_path.txt"
fs::path_wd("my", glue::glue("{Sys.Date()}_path"), ext = "txt")
#> /private/var/folders/w7/jvqhm46x3756vqb0x7fllts80000gn/T/RtmpHOhpew/reprex2e823b91f67b/my/2021-02-16_path.txt

Created on 2021-02-16 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.