Skip to content
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

.here file weirdness on windows #12

Closed
pjrdata opened this issue Jan 30, 2018 · 3 comments
Closed

.here file weirdness on windows #12

pjrdata opened this issue Jan 30, 2018 · 3 comments

Comments

@pjrdata
Copy link

pjrdata commented Jan 30, 2018

I am trying to convert all my 'projects' to use here() rather than setwd() but am having random problems with the here() function (and others) not loving the .here files. I'm not able to use rStudio etc so don't have any sort of .project files. I am just trying to use a text editor along with a .here file which I can see in windows explorer but here() is sometimes not recognising them. Here's a short script that I have used to reproduce what I am seeing:

setwd("C:/!Rprojects/heretest/src")
library(here)
packageVersion("here")
packageVersion("rprojroot")
sessionInfo()
getwd()
list.files(".")
list.files("..")
set_here("..")
set_here("..")
list.files(".")
list.files("..")
here()
dr_here()

Before running the test script, the main project directory just contains the following:
data - an empty directory
doco - an empty directory
output - an empty directory
src - a directory containing a single R script with the above code

I have opened a fresh R session to run the commands above

setwd("C:/!Rprojects/heretest/src")
library(here)
here() starts at C:/!Rprojects/heretest/src
packageVersion("here")
[1] ‘0.1’
packageVersion("rprojroot")
[1] ‘1.3.2’
sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] here_0.1

loaded via a namespace (and not attached):
[1] compiler_3.4.3 backports_1.1.2 rprojroot_1.3-2

getwd()
[1] "C:/!Rprojects/heretest/src"
list.files(".")
[1] "heretest.R"
list.files("..")
[1] "data" "doco" "output" "src"
set_here("..")
Created file .here in C:!Rprojects\heretest
set_here("..")
File .here already exists in C:!Rprojects\heretest
list.files(".")
[1] "heretest.R"
list.files("..")
[1] "data" "doco" "output" "src"
here()
[1] "C:/!Rprojects/heretest/src"
dr_here()
here() starts at C:/!Rprojects/heretest/src, because none of the following criteria apply for this directory or any of its parents:

  • contains a file .here
  • contains a file matching [.]Rproj$ with contents matching ^Version: in the first line
  • contains a file DESCRIPTION with contents matching ^Package:
  • contains a file remake.yml
  • contains a file .projectile
  • contains a directory .git
  • contains a file .git with contents matching ^gitdir:
  • contains a directory .svn
    Use set_here() to create a .here file

So, why does the second set_here() call say that the .here file exists and yet the subsequent here() function and dr_here() do not see it there? It's interesting that the second list.files("..") call also does not show the .here file, even though it's after the set_here("..") calls and the .here file certainly exists at that point.

Now, exiting R and starting a fresh session then running the same commands gives a different result.

setwd("C:/!Rprojects/heretest/src")
library(here)
here() starts at C:/!Rprojects/heretest
packageVersion("here")
[1] ‘0.1’
packageVersion("rprojroot")
[1] ‘1.3.2’
sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] here_0.1

loaded via a namespace (and not attached):
[1] compiler_3.4.3 backports_1.1.2 rprojroot_1.3-2

getwd()
[1] "C:/!Rprojects/heretest/src"
list.files(".")
[1] "heretest.R"
list.files("..")
[1] "data" "doco" "output" "src"
set_here("..")
File .here already exists in C:!Rprojects\heretest
set_here("..")
File .here already exists in C:!Rprojects\heretest
list.files(".")
[1] "heretest.R"
list.files("..")
[1] "data" "doco" "output" "src"
here()
[1] "C:/!Rprojects/heretest"
dr_here()
here() starts at C:/!Rprojects/heretest, because it contains a file .here

this time through, note the following:

  • library(here) has detected the .here file
  • set_here("..") fails both times, as expected, because the file exists
  • list.files("..") still doesn't detect the file (it should shouldn't it?)
  • here() works correctly
  • dr_here() works correctly

Is there perhaps some sort of cached directory information that's causing the .here file to be not detected by here() after it's been created by set_here() on the first time through? Maybe? Just guessing.
list.files doesn't seem to like the file either, but that's a different issue, though possibly related.

here() looks really promising and I'm loving the idea. just getting confused in trying to actually use it on windows. thanks for any help.

@krlmlr
Copy link
Member

krlmlr commented Jan 31, 2018

Thanks. Yes, the here package caches the location of the project root. The main source of confusion seems to be that this isn't updated by set_here(). The documentation and the output now explicitly specifies that you need to restart your R session.

@krlmlr krlmlr closed this as completed in 9f09f83 Jan 31, 2018
@pjrdata
Copy link
Author

pjrdata commented Jan 31, 2018

ok, thankyou

krlmlr added a commit that referenced this issue Feb 1, 2018
- Updated documentation and success message for `set_here()`, now suggests to restart the R session (#12).
@github-actions
Copy link

github-actions bot commented Dec 8, 2020

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 Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants