here 1.0.0 and rprojroot 2.0.2

  Kirill Müller

We’re chuffed to announce the release of here 1.0.0 and rprojroot 2.0.2. here offers a simple way to find your files in a project-oriented workflow. Under the hood, rprojroot implements the logic. Version 1.0.0, the first update since the original CRAN release, introduces a new way to declare the project root. This release also includes an overhaul of the documentation and added safety for path construction.

You can install it from CRAN with:

This blog post shows the two most important user-facing changes: declaring the project root in your scripts and reports, and mixing project-relative and absolute paths. You can see a full list of changes in the release notes for here and rprojroot.

Here I am!

The source of this blog post lives in the index.Rmd file in the content/blog/here-1-0-0 subdirectory of the tidyverse.org repository. It declares its own location:

here::i_am("content/blog/here-1-0-0/index.Rmd")

#> here() starts at /home/kirill/git/R/tidyverse.org

A message describes the location of the project root on my machine. It is probably different on your machine, the purpose of the here package is to help with that situation.

After establishing the project root, the here() function helps navigate the project.

library(here)
library(conflicted)

dir(here("content", "blog", "here-1-0-0"))

#> [1] "index.md"         "index.Rmd"        "thumbnail-sq.jpg" "thumbnail-wd.jpg"

dir(here("content/blog/here-1-0-0"))

#> [1] "index.md"         "index.Rmd"        "thumbnail-sq.jpg" "thumbnail-wd.jpg"

strwrap(readLines(here("CODE_OF_CONDUCT.md"), 5))

#>  [1] "# Contributor Covenant Code of Conduct"                                
#>  [2] ""                                                                      
#>  [3] "## Our Pledge"                                                         
#>  [4] ""                                                                      
#>  [5] "In the interest of fostering an open and welcoming environment, we as" 
#>  [6] "contributors and maintainers pledge to making participation in our"    
#>  [7] "project and our community a harassment-free experience for everyone,"  
#>  [8] "regardless of age, body size, disability, ethnicity, gender identity"  
#>  [9] "and expression, level of experience, nationality, personal appearance,"
#> [10] "race, religion, or sexual identity and orientation."

You can still load1 the here package without calling here::i_am(). The new approach resolves ambiguity and also protects against running the file in the wrong project or outside of a project:

here::i_am("foo/bar.R")

#> Error: Could not find associated project in working directory or any parent directory.
#> - Path in project: foo/bar.R
#> - Current working directory: /home/kirill/git/R/tidyverse.org/content/blog/here-1-0-0
#> Please open the project associated with this file and try again.

Read more at vignette("here", package = "here").

Absolute vs. relative paths

The result of here() is always a character vector with absolute paths. Prior to rprojroot 2.0.2, passing absolute paths to here() resulted in garbage. The update modifies this behavior: if the first argument to here() is an absolute path, the project root is ignored and here() works like file.path():

blog_path <- here("content/blog/here-1-0-0")
blog_path

#> [1] "/home/kirill/git/R/tidyverse.org/content/blog/here-1-0-0"

here("content/blog/here-1-0-0", "index.Rmd")

#> [1] "/home/kirill/git/R/tidyverse.org/content/blog/here-1-0-0/index.Rmd"

here(blog_path, "index.Rmd")

#> [1] "/home/kirill/git/R/tidyverse.org/content/blog/here-1-0-0/index.Rmd"

This allows mixing project-relative and absolute paths without compromising on safety.

Acknowledgements

We would like to thank the contributors who have helped with this release with pull requests and discussion.

here

@ABcreation98, @Alanocallaghan, @antass, @batpigandme, @boshek, @cderv, @chris-prener, @cloversleaves, @cportner, @czeildi, @ghost, @hadley, @ijlyttle, @JamesCuster, @jasonpott, @jennybc, @karldw, @kpjonsson, @lgaborini, @LTzavella, @moodymudskipper, @NoushinN, @nzgwynn, @pjrdata, @prosoitos, @rajanand, @robertamezquita, @Sebaristoteles, @sharlagelfand, @smach, @solarchemist, @StevenHibble, @StevenMMortimer, @swayson, and @yogat3ch.

rprojroot

@BarkleyBG, @batpigandme, @ctbrown, @florisvdh, @hadley, @hansvancalster, @jennybc, @jonathan-g, @jthurner, @kslays, @moodymudskipper, @uribo, and @yonicd.


  1. attach with library() ↩︎