here::here vs tab-autocompletion | benefits of here package?

Dear all,

I'm trying to understand the benefits of here package. I understand the benefits of project-oriented workflow but how here package helps with all this? In that vein, are there any benefits to using here versus simply quotes and tab, that is "tab-autocompletion".

So, this

mtcars <- read_csv("tab-autocompletion")

versus this

mtcars <- read_csv(here::here("data",  "myfile.csv"))

Thank you!

This can be

mtcars <- read_csv(here::here("data/myfile.csv"))

The principal advantage of {here} is that all filenames are relative to the project directory (shown by here()), so you don't have to navigate the directory tree so much.

1 Like

Indeed the goal is to use "tab-completion", but there are 3 almost equivalent ways to do it:

  1. start your script with setwd("/my/path")
  2. use an Rstudio Project (with a .Rproj file)
  3. use {here}

The problem with 1 is that it breaks if you move your project folder, e.g. if you share your scripts with someone else. So, here::here() is basically equivalent to setwd() but robust to sharing or moving folders around on your computer. But if you already use an RStudio Project, it's already doing the equivalent of here, so you can directly use tab-completion.

So if your question is to compare here with an RStudio project, then as far as I understand, there is no advantage, RStudio implements a version of here for you. But if you work outside of RStudio, {here} is useful.

1 Like

This topic was automatically closed 42 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.