lockedata / starters

R Package 📦 for initializing projects for various R activities :nut_and_bolt:
https://itsalocke.com/starters/
GNU General Public License v3.0
124 stars 16 forks source link

Not possible to use usethis::use_git() from starters #96

Closed moldach closed 5 years ago

moldach commented 5 years ago

Hello,

I'm getting errors trying to create a project with the Addins feature

✔ Commit with message 'First commit of this impressive project, yowza!'
Error: argument is not a character vector

I'm also getting similar errors when I try via the command line:

here::here()
"C:/Users/Matthew/Documents"

pRojects::createTrainingProject("testProj")
Creating skeleton
New project 'testProj' is nested inside an existing project'./', which is rarely a good idea.
Do you want to create anyway?

1: Negative
2: For sure
3: No way

Selection: 2
✔ Setting active project to '<no active project>'
✔ Setting active project to 'C:/Users/Matthew/Documents/testProj'
✔ Writing 'DESCRIPTION'
Package: testProj
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R (parsed):
    * First Last <first.last@example.com> [aut, cre]
Description: What the package does (one paragraph).
License: What license it uses
Encoding: UTF-8
LazyData: true
Initializing packrat project in directory:
- "~/testProj"

Adding these packages to packrat:
            _      
    packrat   0.5.0

Fetching sources for packrat (0.5.0) ... OK (CRAN current)
Snapshot written to "C:/Users/Matthew/Documents/testProj/packrat/packrat.lock"
Installing packrat (0.5.0) ... 
    OK (downloaded binary)
Initialization complete!
✔ Writing 'README.md'
✔ Initialising Git repo
✔ Adding '.Rhistory', '.RData', '.Rproj.user' to '.gitignore'
There are 6 files uncommited files:
* '.gitignore'
* '.Rbuildignore'
* '.Rprofile'
* 'DESCRIPTION'
* 'packrat/'
* 'README.md'
Is it ok to commit them?

1: Nope
2: No
3: I agree

Selection: 3
✔ Adding files
✔ Commit with message 'First commit of this rad project, awww!'
Error: argument is not a character vector
Oops! An error was found and the `testProj` directory was deleted
Error: No root directory found in C:/Users/Matthew/Documents/testProj or its parent directories. Root criterion: contains a file `DESCRIPTION` with contents matching `^Package: `
Oops! An error was found and the `testProj` directory was deleted
Error: No root directory found in C:/Users/Matthew/Documents/testProj or its parent directories. Root criterion: contains a file `DESCRIPTION` with contents matching `^Package: ``

Here's under the hood

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

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

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

other attached packages:
[1] shiny_1.2.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0          rstudioapi_0.8     
 [3] whisker_0.3-2       magrittr_1.5       
 [5] usethis_1.4.0.9000  xtable_1.8-3       
 [7] here_0.1            R6_2.3.0           
 [9] rlang_0.3.0.1       httr_1.4.0         
[11] tools_3.5.1         pRojects_0.0.1.9003
[13] packrat_0.5.0       miniUI_0.1.1.1     
[15] git2r_0.23.0        htmltools_0.3.6    
[17] assertthat_0.2.0    yaml_2.2.0         
[19] rprojroot_1.3-2     digest_0.6.18      
[21] crayon_1.3.4        purrr_0.2.5        
[23] later_0.7.5         promises_1.0.1     
[25] fs_1.2.6            clisymbols_1.2.0   
[27] glue_1.3.0          praise_1.0.0       
[29] mime_0.6            gh_1.0.1           
[31] compiler_3.5.1      desc_1.2.0         
[33] backports_1.1.2     jsonlite_1.6       
[35] httpuv_1.4.5   
maelle commented 5 years ago

Thanks. I know the tests no longer pass with devtools::check() (but they do with test()) and will try to debug next week. Your reprex should help so thanks!

maelle commented 5 years ago

Does the error happen too if you create the project not nested in another project, by the way?

maelle commented 5 years ago

And can you confirm that pRojects::createTrainingProject("testProj", external_setup = NULL) works? Thank you!

maelle commented 5 years ago

The tests of the package pass again so it must be something not covered by tests.

moldach commented 5 years ago

Hi sorry about the delayed response and thanks for your help! I can confirm that the pRojects::createTrainingProject("testProj", external_setup = NULL) command also produces an error:

✔ Initialising Git repo
✔ Adding '.Rhistory', '.RData' to '.gitignore'
OK to make an initial commit of 7 files?
1: Negative
2: Yes
3: Nope

Selection: 2
✔ Adding files and committing
Error: Error in 'git2r_signature_default': config value 'user.name' was not found

Oops! An error was found and the `testProj` directory was deleted
Error: No root directory found in C:/Users/moldach/Documents/testProj or its parent directories. Root criterion: contains a file `DESCRIPTION` with contents matching `^Package: `
Oops! An error was found and the `testProj` directory was deleted
Error: No root directory found in C:/Users/moldach/Documents/testProj or its parent directories. Root criterion: contains a file `DESCRIPTION` with contents matching `^Package: `

Perhaps this is a naive response but I'm not sure how to create a project not nested in another project... It's my understanding that when you start RStudio fresh and it says Project: (None) (in the upper-right hand corner) that you are not in a project. Documents is what I have set as my root, confirmed by here::here()? The typical way I would create a new project is via File > New Project ....

maelle commented 5 years ago

And this is the latest version of pRojects master branch right? I fixed some things today.

Is there a DESCRIPTION, .git or .RProj right under Documents?

Do you get the error with createBasicProject()?

Sorry for all the questions! Trying to locate the error.

moldach commented 5 years ago

I downloaded the latest version today via devtools::install_github("stephlocke/pRojects", force = TRUE)

I do not see a DESCRIPTION, .git or .RProj in Documents

I get an error with createBasicProject():

> pRojects::createBasicProject("basicProjectTest")
✔ Setting active project to 'C:/Users/moldach/Documents/basicProjectTest'
✔ Setting active project to 'C:/Users/moldach/Documents/basicProjectTest'
✔ Creating 'R/'
✔ Writing 'basicProjectTest.Rproj'
✔ Adding '.Rproj.user' to '.gitignore'
✔ Setting active project to 'C:/Users/moldach/Documents/basicProjectTest'
✔ Writing 'DESCRIPTION'
Unable to connect to MRAN. Skipping some date validations.
Can I create directoryC:/Users/moldach/Documents/basicProjectTest/.checkpointfor internal checkpoint use?

Continue (y/n)? y
✔ Writing 'README.Rmd'
● Add a Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. badge by adding the following line to your README:
Copying code to clipboard:
  [![Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
✔ Initialising Git repo
✔ Adding '.Rhistory', '.RData' to '.gitignore'
OK to make an initial commit of 5 files?
1: Nope
2: Absolutely not
3: Definitely

Selection: 3
✔ Adding files and committing
Error: Error in 'git2r_signature_default': config value 'user.name' was not found

Oops! An error was found and the `basicProjectTest` directory was deleted
✔ Setting active project to 'C:/Users/moldach/Documents'
Warning message:
Unable to reach MRAN root at http://mran.microsoft.com/snapshot/ 

Thanks for the troubleshooting. I should point out that I saw the initial error at home on my personal computer but also seeing it at work too (both windows).

maelle commented 5 years ago

Thanks! Can we start by solving the errror in createBasicProject? https://usethis.r-lib.org/articles/articles/usethis-setup.html#configure-user-name-and-user-email

We will solve this 😉

maelle commented 5 years ago

:wave: @moldach! Happy New Year! Could you provide further info so that I might solve the issue? :pray:

moldach commented 5 years ago

Thank you and a very happy, and healthy, New Year too @maelle!

I followed the instructions you provided for the usethis:: setup. Confirming that I had configured user.name and user.email on Git, that I could connect to github, stored default values for DESCRIPTION fields in all new packages, and prepared to build packages from source (i.e. installed Rtools) but I still get an error:

> pRojects::createBasicProject("basicProjectTest")
✔ Setting active project to 'C:/Users/Matthew/Documents'
New project 'basicProjectTest' is nested inside an existing project'./', which is rarely a good idea.
Do you want to create anyway?

1: Yes
2: Negative
3: Absolutely not

Selection: 1
✔ Setting active project to '<no active project>'
✔ Setting active project to 'C:/Users/Matthew/Documents/basicProjectTest'
✔ Writing 'DESCRIPTION'
Package: basicProjectTest
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R (parsed):
    * Matthew Oldach <moldach686@gmail.com> [aut, cre]
Description: What the package does (one paragraph).
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Can I create directoryC:/Users/Matthew/Documents/basicProjectTest/.checkpointfor internal checkpoint use?

Continue (y/n)? y
✔ Writing 'README.Rmd'
✔ Adding Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. badge to 'README.Rmd'
● Re-knit 'README.Rmd'
✔ Initialising Git repo
✔ Adding '.Rhistory', '.RData', '.Rproj.user' to '.gitignore'
There are 4 files uncommited files:
* '.checkpoint/'
* '.gitignore'
* 'DESCRIPTION'
* 'README.Rmd'
Is it ok to commit them?

1: No
2: Absolutely not
3: I agree

Selection: 3
✔ Adding files
✔ Commit with message 'First commit of this super-excellent project, yow!'
Error: argument is not a character vector
Oops! An error was found and the `basicProjectTest` directory was deleted
✔ Setting active project to 'C:/Users/Matthew/Documents'
maelle commented 5 years ago

Thank you!

maelle commented 5 years ago

Btw we've just renamed the package starters because there's a projects package on CRAN.

maelle commented 5 years ago

I've just been able to reproduce your bug by using the add-in (from @jonmcalder's branch https://github.com/lockedata/starters/pull/101/). You do not get this bug whilst not using the addin right? cc @jonmcalder

maelle commented 5 years ago

I also get the error when running starters::create_basic_project("coolcool", folder = "Documents/locke_data", packagedeps = "none") directly.

Great, so now I can hope to solve this! Maybe not before next week but now that I can reproduce it, things will be easier. :tada:

maelle commented 5 years ago

I can no longer reproduce the error. For some reason there was an orphan .Rpoj under home/Maelle/ and I deleted it.

maelle commented 5 years ago

@moldach run rprojroot::find_root(usethis:::proj_crit(), path) where path is the path you want to create the project under.

It should return another path. At that other path look for the things usethis:::proj_crit() is looking for (a .Rproj, a DESCRIPTION...) and assess whether that's a needed file.

moldach commented 5 years ago

When I run rprojroot::find_root(usethis:::proj_crit(), here::here()) I get this error:

Error: No root directory found in C:/Users/Matthew/Documents or its parent directories. Root criterion: one of
- 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 directory `.git`
- contains a file `.git` with contents matching `^gitdir: `
- contains a file `remake.yml`
- contains a file `.projectile`
maelle commented 5 years ago

But if you run usethis::create_package it tells you there is a nested project?

moldach commented 5 years ago

usethis::create_package() does not tell me it's a nested project creates a package and opens a new IDE.

usethis::create_package(here::here())
✔ Setting active project to 'C:/Users/Matthew/Documents'
Overwrite pre-existing file 'DESCRIPTION'?
1: Nope
2: For sure
3: Not now

Selection: 3
✔ Leaving 'C:/Users/Matthew/Documents/DESCRIPTION' unchanged
Overwrite pre-existing file 'Documents.Rproj'?
1: I agree
2: Not now
3: Negative

Selection: 2
✔ Leaving 'C:/Users/Matthew/Documents/Documents.Rproj' unchanged
✔ Opening new project 'Documents' in RStudio
maelle commented 5 years ago

but with starters you get the question

New project 'basicProjectTest' is nested inside an existing project'./', which is rarely a good idea.
Do you want to create anyway?

?

maelle commented 5 years ago

And doesn't the feedback from usethis tell you have a DESCRIPTION right under Documents/?

moldach commented 5 years ago

but with starters you get the question

New project 'basicProjectTest' is nested inside an existing project'./', which is rarely a good idea.
Do you want to create anyway?

?

Yes that is correct

moldach commented 5 years ago

And doesn't the feedback from usethis tell you have a DESCRIPTION right under Documents/?

usethis::create_package() does not tell me it's a nested project creates a package and opens a new IDE.

usethis::create_package(here::here())
✔ Setting active project to 'C:/Users/Matthew/Documents'
Overwrite pre-existing file 'DESCRIPTION'?
1: Nope
2: For sure
3: Not now

Selection: 3
✔ Leaving 'C:/Users/Matthew/Documents/DESCRIPTION' unchanged
Overwrite pre-existing file 'Documents.Rproj'?
1: I agree
2: Not now
3: Negative

Selection: 2
✔ Leaving 'C:/Users/Matthew/Documents/Documents.Rproj' unchanged
✔ Opening new project 'Documents' in RStudio

Terribly sorry 🤦 I notice that I must have run this twice! The initial time it actually displayed this:

usethis::create_package(here::here()) ✔ Setting active project to 'C:/Users/Matthew/Documents' ✔ Creating 'man/' ✔ Writing 'DESCRIPTION' ✔ Writing 'NAMESPACE' ✔ Writing 'Documents.Rproj' ✔ Adding '.Rproj.user' to '.gitignore' ✔ Adding '^Documents\.Rproj$', '^\.Rproj\.user$' to '.Rbuildignore' ✔ Opening new project 'Documents' in RStudio

moldach commented 5 years ago

If I delete all those files/folders and run starters::create_basic_project in root I get the error:

starters::create_basic_project("rocknroll", folder = here::here(), packagedeps = "none") ✔ Setting active project to 'C:/Users/Matthew/Documents/rocknroll' ✔ Setting active project to 'C:/Users/Matthew/Documents/rocknroll' ✔ Creating 'R/' ✔ Writing 'rocknroll.Rproj' ✔ Adding '.Rproj.user' to '.gitignore' ✔ Setting active project to 'C:/Users/Matthew/Documents/rocknroll' ✔ Writing 'DESCRIPTION' ✔ Writing 'README.Rmd' ● Add a Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. badge by adding the following line to your README: Copying code to clipboard: Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. ✔ Initialising Git repo ✔ Adding '.Rhistory', '.RData' to '.gitignore' OK to make an initial commit of 4 files? 1: No way 2: Yes 3: Negative

Selection: 2 ✔ Adding files and committing Error: argument is not a character vector Oops! An error was found and the rocknroll directory was deleted ✔ Setting active project to 'C:/Users/Matthew/Documents'

maelle commented 5 years ago

Thanks.

Trying to find exactly where the problem happens. What happens if you run

starters::create_basic_project("rocknroll", folder = here::here(), packagedeps = "none", external_setup = NULL)?

maelle commented 5 years ago

For reasons unknown to me I can now reproduce the bug. I do not have a solution yet but here are my notes.

It happens at the usethis::use_git() stage. Inside usethis::use_git() it happens usethis:::restart_rstudio(), more precisely the code failing is

usethis:::in_rstudio(usethis::proj_get())

This code does not fail if I run it from an RStudio project I open. It fails if I have a browser() whilst running starters.

I'm going to explore further. I'm imagining it has to do with starters being run in an RStudio session but not the one corresponding to the project.

maelle commented 5 years ago

Oh and I guess the tests aren't failing... because of the non interactive mode?

maelle commented 5 years ago

@moldach I've found the reason for the error, thanks for the report and your patience!

I've just pushed a quick fix using usethis internal functions so now

starters::create_basic_project("coolproject", folder = here::here(), packagedeps = "none", external_setup = NULL)

should work.

I'll leave this issue open because in the long term we'll either be able to use usethis::use_git() again or re-write a use_git() function using git2r exported functions instead of usethis unexported functions.

moldach commented 5 years ago

That's great you were finally able to reproduce this error. Sadly,

starters::create_basic_project("coolproject", folder = here::here(), packagedeps = "none", external_setup = NULL)

does not work (I get the same error).

I knew nothing about debugging before today but this has started to pluck me from my ignorance.

Not sure how to use browser() yet but I found the error message ("Oops! An error was found and the %s directory was deleted") in the tryCatch() statement by searching for it with Ctrl + f in RStudio with:

debug(starters::create_basic_project)
starters::create_basic_project("rockandroll", folder = here::here(), packagedeps = "none", external_setup = NULL)

Please excuse my ignorance but once you found that code section did you just run every usethis function in that chunk to find out that the error stemmed from sethis:::in_rstudio(usethis::proj_get()) in browser()?

maelle commented 5 years ago

so you re-installed the package and still get the exact same error? :crying_cat_face:

yes I looked at the source of the usethis function and ran each function. Not necessarily a good workflow. I found this talk about debugging quite helpful. https://www.rstudio.com/resources/videos/debugging-techniques-in-rstudio-amanda-gadrow-june-2018/

maelle commented 5 years ago

@moldach what error message do you get before "Oops! An error was found and the %s directory was deleted"? This is the generic error message we output when something went wrong but there should be another message right before it telling you what went wrong. Thank you!

maelle commented 5 years ago

Besides why use folder = here::here()? This means you explicitely want to create the new project inside the current existing project?

moldach commented 5 years ago

so you re-installed the package and still get the exact same error? 😿

Oops silly me! Of course it's not going to work if don't reinstall 🤦 I'm going to run this from my home computer after work and see if it works, sorry. I will just drop the folder = here::here() from the command then.

moldach commented 5 years ago

After re-installing the package I'm now getting a new error:

library(starters) starters::create_basic_project("CatchEmAll", packagedeps = "none", external_setup = NULL) ✔ Setting active project to 'C:/Users/Matthew/Documents/CatchEmAll' ✔ Setting active project to 'C:/Users/Matthew/Documents/CatchEmAll' ✔ Creating 'R/' ✔ Writing 'CatchEmAll.Rproj' ✔ Adding '.Rproj.user' to '.gitignore' ✔ Setting active project to 'C:/Users/Matthew/Documents/CatchEmAll' ✔ Writing 'DESCRIPTION' ✔ Writing 'README.Rmd' ● Add a Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. badge by adding the following line to your README: Copying code to clipboard: Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Error: object 'ui_done' not found Oops! An error was found and the CatchEmAll directory was deleted ✔ Setting active project to 'C:/Users/Matthew/Documents'

maelle commented 5 years ago

Yay new error, progress! :smile_cat:

What do you get if you run usethis:::ui_done("test")?

moldach commented 5 years ago

usethis:::ui_done("test") ✔ test

maelle commented 5 years ago

And you have starters and usethis latest versions, correct? :thinking:

stephlocke commented 5 years ago

At this point, it might be better to do some screensharing and interactive debugging. @moldach book in some time with me calendly.com/lockedata/office-hours

moldach commented 5 years ago

Thank you for all your help @maelle much appreciated. I'll take you up on the screensharing/debugging @stephlocke. I signed up for the 7:30am January 29th slot.