-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
assert_here() #27
Comments
A collaborator just fell into this trap. See the RStudio behaviour when opening by file association:
In their case they wound up in their home directory, which seems a good candidate for a message: |
We could also look for a specific file/directory in the project, and give a nicer error message. Need to mull over it. |
I prefer solving this with documentation. |
I added a section to the "Getting started" article, feedback welcome. |
Thinking about this again, any solution appears to make I'm not sure what to suggest. Perhaps if |
I'm not sure about the redundancy.
I think this is about failing early, failing fast, failing clearly. Does the text at https://here.r-lib.org/articles/here.html#enforce-project-oriented-workflow-1 need more clarification? |
I don't think this describes the situation in this thread, but I might not have fully understood it. I think the steps to reproduce this behaviour are as follows.
# proj1/script1.R
getwd()
library(here)
file.exists(here("data1.csv")) # proj1/script2.R
getwd()
library(here)
file.exists(here("data2.csv"))
The advice in the documentation is to use a project-oriented workflow, along with some defensive code. I think this advice makes the use of the {here} package redundant, because:
I do think a project-oriented workflow should be encouraged when all collaborators use RStudio, and {here} should be encouraged when no collaborators use RStudio. But I would find it difficult to persuade people to use {here} if they still have to write defensive code, hence my suggestion to make |
Thanks. Your described workflow is consistent with my understanding of the problem. Both the starting directory and here's notion of the project root could be anything. Scripts that rely on {here} will fail in varying degrees -- from failure to open a file for reading to silent failure after writing a file to an unexpected location. Ideally all scripts using {here} would fail loudly.
This coincides with the problem that there's no well-defined way for an R script to know its own path. The kimisc and rprojroot packages have functions that now moved to {whereami} (thanks @yonicd), and {this.path} seems to reimplement this (on CRAN since yesterday). The suggested |
Thanks for reconsidering this. |
- New `here::i_am()` offers a new recommended way to declare the project root. Instead of relying on special files or directories that indicate the project root, each script and report now can declare its own location relative to the project root (#27).
I was reading this, among other things, as part of digesting the recent changes to here. This thread was helpful for getting re-oriented to the safety problem, which I do acknowledge (and which motivated me to open the issue). The concrete demo @nacnudus gives really describes what I see as the heart of this matter. However, I do want to push back on this:
That only holds as long as you don't have anything you plan to knit in a subdirectory of the project. Once you've got an |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
It would be interesting to consider an
assert_here()
function.Inspired by this Twitter conversation with Emile Latour (@emilelatour).
Problem: you use Projects and the here package and life is awesome. But your collaborator still clicks on an Rmd in the Finder and it just opens in RStudio, in whatever Project (or non-Project) they happen to have open. Now all the path-building code doesn't work as planned when they run chunks interactively (knitting the whole document still works fine for them).
If you want to make a
.R
or.Rmd
file more resilient to this and you feel like the Project's name is pretty stable, you could puthere::assert_here("PROJECT_NAME")
at the top as a way of raising an alarm when the workflow violates expectations.assert_here()
would be something likeassertthat::assert_that(identical(basename(here::here()), “PROJECT_NAME”))
.The text was updated successfully, but these errors were encountered: