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

proj_path() not necessarily absolutized for create_*() #227

Closed
adomingues opened this Issue Jan 25, 2018 · 8 comments

Comments

Projects
None yet
2 participants
@adomingues
Copy link

adomingues commented Jan 25, 2018

Maybe this is an intended behaviour, but I am not sure and this report. Reproducible example:
(using console R)

library(usethis)
pkg_dir <- file.path(".", "testLicense")
create_package(pkg_dir)
Changing active project to testLicenseCreating 'R/'Creating 'man/'Writing 'DESCRIPTION'Writing 'NAMESPACE'Changing working directory to './testLicense'

use_mit_license("António Domingues")
# Error: File file does not exist
getwd()
[1] "/home/adomingu/sandbox/testLicense"

The error is also a little strange, File file does not exist (sic).

If I now change to the package directory, outside R:

cd /home/adomingu/sandbox/testLicense
R
library(usethis)
use_mit_license("António Domingues")
✔ Setting License field in DESCRIPTION to 'MIT + file LICENSE'Writing 'LICENSE.md'Adding '^LICENSE\\.md$' to '.Rbuildignore'Writing 'LICENSE'

all is fine and dandy.

I repeated the test using Rstudio (Version 1.1.383) and the error is now gone, that is, use_mit_license works as intended. I wonder if there is something extra that Rstudio does in the background that is not replicated in console ("vanilla") R.

 devtools::session_info()
Session info ------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.3 (2017-11-30)
 system   x86_64, linux-gnu           
 ui       X11                         
 language en_US                       
 collate  en_US.UTF-8                 
 tz       Europe/Berlin               
 date     2018-01-25                  

Packages ----------------------------------------------------------------------
 package    * version    date       source                          
 assertthat   0.2.0      2017-04-11 CRAN (R 3.4.1)                  
 backports    1.1.2      2017-12-13 cran (@1.1.2)                   
 base       * 3.4.3      2017-12-01 local                           
 clisymbols   1.2.0      2017-05-21 cran (@1.2.0)                   
 compiler     3.4.3      2017-12-01 local                           
 crayon       1.3.4      2017-09-16 CRAN (R 3.4.1)                  
 datasets   * 3.4.3      2017-12-01 local                           
 desc         1.1.1      2017-08-03 cran (@1.1.1)                   
 devtools     1.13.4     2017-11-09 CRAN (R 3.4.2)                  
 digest       0.6.14     2018-01-14 CRAN (R 3.4.3)                  
 graphics   * 3.4.3      2017-12-01 local                           
 grDevices  * 3.4.3      2017-12-01 local                           
 memoise      1.1.0      2017-04-21 CRAN (R 3.4.1)                  
 methods    * 3.4.3      2017-12-01 local                           
 R6           2.2.2      2017-06-17 CRAN (R 3.4.1)                  
 rprojroot    1.3-2      2018-01-03 CRAN (R 3.4.3)                  
 rstudioapi   0.7        2017-09-07 CRAN (R 3.4.1)                  
 stats      * 3.4.3      2017-12-01 local                           
 usethis    * 1.2.0      2018-01-19 CRAN (R 3.4.3)                  
 utils      * 3.4.3      2017-12-01 local                           
 whisker      0.3-2      2013-04-28 CRAN (R 3.4.1)                  
 withr        2.1.1.9000 2018-01-02 Github (jimhester/withr@df18523)
@jennybc

This comment has been minimized.

Copy link
Member

jennybc commented Jan 25, 2018

Hmmm .... this works for me outside RStudio. Can you add proj_get() to your failing Console example, before use_mit_license(), and also show me a traceback()? Also, will you confirm the version of usethis in your Console session is also 1.2.0, as I see in session info above. You can use packageVersion("usethis").

@adomingues

This comment has been minimized.

Copy link
Author

adomingues commented Jan 25, 2018

I was also surprised myself since it worked perfectly just a couple of weeks ago. (Thank you for creating the package by the way - very useful).

Back to testing.

proj_get()
[1] "./testLicense"
se_mit_license("António Domingues")
Error: File file does not exist

The error is reproducible on my system (Ubuntu 16.04).

Now the traceback:

9: stop(assertError(attr(res, "msg")))
8: assert_that(is_existing_file(file))
7: idesc_create_file(self, private, file)
6: idesc_create(self, private, cmd, file, text, package)
5: .subset2(public_bind_env, "initialize")(...)
4: description$new(file = file)
3: desc::desc_get(name, file = base_path)
2: use_description_field("License", "MIT + file LICENSE", overwrite = TRUE)
1: use_mit_license("António Domingues")

And the package version is indeed 1.2.0.

@jennybc

This comment has been minimized.

Copy link
Member

jennybc commented Jan 25, 2018

I think this is complaining about not being able to find the DESCRIPTION file, which I don't understand.

BTW why are you specifying the "." in pkg_dir? Why do you want the path to be "./testLicense" instead of just "testLicense"? I suspect that is neither here nor there, but I'm dropping it.

Can you run this:

library(usethis)
pkg_dir <- "testLicense"
create_package(pkg_dir)
proj_get()
getwd()
list.files()
desc::desc_get("License", file = ".")
desc::desc_get("License", file = pkg_dir)
@adomingues

This comment has been minimized.

Copy link
Author

adomingues commented Jan 26, 2018

BTW why are you specifying the "." in pkg_dir? Why do you want the path to be "./testLicense" instead of just "testLicense"?

Blindly following the instructions, except that instead of pointing to "tmp" directory, I set the current directory.

I suspect that is neither here nor there, but I'm dropping it.

Using create_package("testLicence") straight still returns the above error though. The error also persists when I tested on a different system, Debian server with R version 3.3.2. However, and for the sake of completeness, following the readme instructions works without a problem:

library(usethis)

# Create a new package -------------------------------------------------
tmp <- file.path(tempdir(), "mypkg")
create_package(tmp)
Changing active project to mypkgCreating 'R/'Creating 'man/'Writing 'DESCRIPTION'Writing 'NAMESPACE'Changing working directory to '/tmp/Rtmp20GJaq/mypkg'
> use_mit_license("My Name")
✔ Setting License field in DESCRIPTION to 'MIT + file LICENSE'Writing 'LICENSE.md'Adding '^LICENSE\\.md$' to '.Rbuildignore'Writing 'LICENSE'

So I really have no idea what is going on.

Can you run this:

Error is still there.

library(usethis)
pkg_dir <- "testLicense"
create_package(pkg_dir)
Changing active project to testLicense
✔ Creating 'R/'
✔ Creating 'man/'
✔ Writing 'DESCRIPTION'
✔ Writing 'NAMESPACE'
✔ Changing working directory to 'testLicense'
proj_get()
[1] "testLicense"
getwd()
[1] "/home/adomingu/sandbox/testLicense"
list.files()
[1] "DESCRIPTION" "man"         "NAMESPACE"   "R"          
desc::desc_get("License", file = ".")
               License 
"What license it uses" 
desc::desc_get("License", file = pkg_dir)
Error: File file does not exist

Maybe it is something stupid that I am missing, but I can't figure it out.

@jennybc

This comment has been minimized.

Copy link
Member

jennybc commented Jan 26, 2018

Well, I see the problem now.

On my system, working outside of RStudio, proj_get() returns an absolute path:

> library(usethis)
> pkg_dir <- "~/tmp/testLicense"
> create_package(pkg_dir)
Changing active project to testLicenseChanging working directory to '/Users/jenny/tmp/testLicense'
> proj_get()
[1] "/Users/jenny/tmp/testLicense"
> use_mit_license("jenny")
✔ Setting License field in DESCRIPTION to 'MIT + file LICENSE'Writing 'LICENSE.md'Adding '^LICENSE\\.md$' to '.Rbuildignore'Writing 'LICENSE'

whereas you are getting just testLicense. Once we change the working directory, this doesn't make any sense as the project directory.

So I need to sort out this path difference.

As a temporary workaround, you should set the project to the absolute path of current working directory. You can use proj_set(). You might need to use force = TRUE.

@jennybc

This comment has been minimized.

Copy link
Member

jennybc commented Jan 26, 2018

Will you install from this branch and see if it is fixed?

devtools::install_github("r-lib/usethis@really-normalize")
@adomingues

This comment has been minimized.

Copy link
Author

adomingues commented Jan 26, 2018

devtools::install_github("r-lib/usethis@really-normalize")

It works! Thank you.

@adomingues adomingues closed this Jan 26, 2018

@jennybc jennybc changed the title use licence fails when working directory is not the package directory use_mit_licence() fails on Ubuntu, outside of RStudio Jan 26, 2018

@jennybc jennybc reopened this Jan 26, 2018

@jennybc

This comment has been minimized.

Copy link
Member

jennybc commented Jan 26, 2018

Great! I've re-opened because I need to add some tests and edit the NEWS. I'll close this when I merge the fix.

@jennybc jennybc changed the title use_mit_licence() fails on Ubuntu, outside of RStudio proj_path() not necessarily absolutized for create_*() on Ubuntu/Debian, outside of RStudio Jan 26, 2018

jennybc added a commit that referenced this issue Jan 26, 2018

@jennybc jennybc changed the title proj_path() not necessarily absolutized for create_*() on Ubuntu/Debian, outside of RStudio proj_path() not necessarily absolutized for create_*(), outside of RStudio Jan 26, 2018

@jennybc jennybc changed the title proj_path() not necessarily absolutized for create_*(), outside of RStudio proj_path() not necessarily absolutized for create_*() Jan 26, 2018

@jennybc jennybc added the bug label Jan 26, 2018

@jennybc jennybc closed this in #228 Jan 26, 2018

jennybc added a commit that referenced this issue Jan 26, 2018

Re-normalize path, after it is guaranteed to exist (#228)
* Add failing test

* Re-normalize path, after it is guaranteed to exist

Fixes #227

* Extend fix and test to non-package project case

* NEWS bullet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.