Skip to content

Feature request: reset the starting point of here() automatically to the directory containing .here when set_here() is used #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
prosoitos opened this issue Sep 24, 2018 · 9 comments · Fixed by #55

Comments

@prosoitos
Copy link

prosoitos commented Sep 24, 2018

Thanks a ton for the package. I love it and am following in Jenny's path in advocating its use instead of setwd().

My issue is closely related to jennybc/here_here#3 and #24.

Problem:

You need to create a .here file in a directory because it isn't big nor important enough to justify doing version control on it. But that directory is nested in another one which has a .something file that here will use to set the "project" root. Now, using set_here() will create the .here file just fine, but here has already been set and there is no way to update it unless restarting the R process (which creates a very awkward workflow and impairs automation).

As mentioned in other issues re-running library(here) (which wouldn't be a great solution anyway) has no effect. And I even tried running here::set_here() before running library(here), but that does not work either. Reloading R is the only solution.

Suggestion:

set_here() does what it should and work great when here hasn't been set on a wrong target (due to something higher in the path than the intended project root), but fails when a wrong target was found. Having a function that would automatically run while using set_here() to reset here to the location of the .here file that has just been created would be more robust and cover situations such as the one I am describing.

@prosoitos
Copy link
Author

prosoitos commented Sep 24, 2018

Note: when one creates a .here file, it is obviously with the intention of using it as a marker for the project root. So having here reset any project root it might have set upon being loaded to the location of that newly created .here file seems sensible and that's why I feel that this should be done automatically by the function set_here() rather than by another function that one would have to run in situations such as the one I described above.

@prosoitos
Copy link
Author

prosoitos commented Sep 24, 2018

Noobie's alert: this might be a naive comment and I could be totally wrong on this. But I feel that here must run some function to set the location of the project root when it is first loaded (or first used, as when I tried running here::set_here()). So my feature request might just be a question of automatically re-running that function which already exists as soon as the .here file is created.

I can try to look at the code and see if I can come up with something that works to submit a PR if you were open to the suggestion.

@robertamezquita
Copy link

Totally agreed with this, just want to say that sometimes the here package miscalculates the root the first time around (especially when setting up a new package/analysis), and sometimes having to restart an R session is onerous especially on a cluster (sometimes start the R session in the wrong place, and then lose X11 connectivity, and so on..tl;dr restarting R is a pain).

@prosoitos
Copy link
Author

I recently encountered other situations in which I would have liked to be able to reset the project root without having to relaunch R (after some change in directory structure while running an R session). So an alternative to having set_here() reset the root after it is run would be to create the function reset_here() which could reset the root.

Running this function would solve all situations in which the root was set somewhere unintented or needs to be reset after some change.

@tnoomah
Copy link

tnoomah commented Jan 14, 2020

I found this issue thread because I was also trying to find a way to reset here mid session. I thought I'd comment for anyone else who finds this in the future because I was able to find a workaround.

Start with your first .here path location

library(here)

here() starts at C:/Users/gtheot/Documents

Then to reset, detach here, reset the working directory with setwd, and when you reload here, you'll be in the new directory

detach("package:here", unload=TRUE)
setwd("C:/Users/gtheot/Desktop")
library(here)

here() starts at C:/Users/gtheot/Desktop

@reidwil
Copy link

reidwil commented Jan 30, 2020

@tnoomah does this fix it for future referencing of here()? If not, having to manually setwd every time to get the right here() path is now completely defeating this package's purpose

@tnoomah
Copy link

tnoomah commented Feb 6, 2020

@reidwil when you detach here, set the working directory manually and reload here, you create a new .here file which will be the point of reference for here going forward in your session. You only have to manually setwd when you want to change the location of your .here file, after that you can use here like you normally would.

@krlmlr
Copy link
Member

krlmlr commented Nov 12, 2020

After set_here() you will need to start a new R session. You could also get away with unloadNamespace("here") if necessary. I documented this in the "Getting started" article, feedback welcome.

@github-actions
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants