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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to report the State of the Project and Working Directory #426

Merged
merged 9 commits into from Aug 8, 2018

Conversation

@jennybc
Copy link
Member

@jennybc jennybc commented Aug 5, 2018

Objective: create a reporter or doctor function that reveals

  • working directory
  • active usethis project
  • active RStudio project

The print() method goes on to make observations about the state of things and to suggest ways to get back to the ideal situation: working directory == active usethis project == active RStudio project.

Intended for use in remote debugging / reprexing, live workshops, writing, when people get into weird situations due to awkward workflow (or a usethis bug).

Questions I have:

  • Overall 馃憤 or 馃憥?
  • Is this a good name? Recall, there are vague plans to add some other reporter/doctor functions.
  • Should I only offer advice on what to do or should there be functions to facilitate?
    • For example, setwd(rstudioapi::getActiveProject()) might deserve nicer packaging. This is equivalent to IDE workflows: Session > Set Working Directory > To Project Directory or Files pane > click on RStudio icon to focus file browser on Project > More ... > Set As Working Directory.
@jennybc
Copy link
Member Author

@jennybc jennybc commented Aug 6, 2018

Situation normal (no RStudio, because reprex/callr):

library(usethis)

proj_sitrep()
#>       working_directory:     '/Users/jenny/rrr/usethis'
#>     active_usethis_proj:     NULL
#>     active_rstudio_proj:     NULL
#> 
#> 鈼 There is currently no active usethis project.
#>   usethis attempts to activate a project upon first need.
#>   Call `proj_get()` to explicitly initiate project activation.

proj_get()
#> 鉁 Setting active project to '/Users/jenny/rrr/usethis'
#> /Users/jenny/rrr/usethis

proj_sitrep()
#>       working_directory:     '/Users/jenny/rrr/usethis'
#>     active_usethis_proj:     '/Users/jenny/rrr/usethis'
#>     active_rstudio_proj:     NULL

Created on 2018-08-05 by the reprex package (v0.2.0.9000).


What this looks like in RStudio

library(usethis)

proj_sitrep()
#>       working_directory:     '/Users/jenny/rrr/usethis'
#>     active_usethis_proj:     NULL
#>     active_rstudio_proj:     '/Users/jenny/rrr/usethis'
#> 
#> 鈼 There is currently no active usethis project.
#>   usethis attempts to activate a project upon first need.
#>   Call `proj_get()` to explicitly initiate project activation.

proj_get()
#> 鉁 Setting active project to '/Users/jenny/rrr/usethis'
#> /Users/jenny/rrr/usethis

proj_sitrep()
#>       working_directory:     '/Users/jenny/rrr/usethis'
#>     active_usethis_proj:     '/Users/jenny/rrr/usethis'
#>     active_rstudio_proj:     '/Users/jenny/rrr/usethis'

Creating a much more disordered state, in RStudio:

> devtools::load_all("~/rrr/usethis")
Loading usethis
鉁 Setting active project to '/Users/jenny/rrr/usethis'

> ## set working to directory to NOT this RStudio Project
> setwd("~")

> ## set usethis project to something below tempdir
> usethis:::scoped_temporary_project()
鉁 Switching to a temporary project!
鈼 Restore current project with: `proj_set("/Users/jenny/rrr/usethis")`

> proj_sitrep()
      working_directory:     '/Users/jenny'
    active_usethis_proj:     '/private/var/folders/vr/gzrbtprx6ybg85y5pvwm1ct40000gn/T/Rtmp88agSz/aaa335b7f4aee01'
    active_rstudio_proj:     '/Users/jenny/rrr/usethis'

鈼 Your working directory is not the same as the active usethis project.
  To set working directory to the project: `setwd(proj_get())`
  To activate project in working directory: `proj_set(getwd())`
鈼 Your working directory is not the same as the active RStudio Project.
  To set working directory to the Project: `setwd(rstudioapi::getActiveProject())`
鈼 Your active RStudio Project is not the same as the active usethis project.
  To set usethis project to RStudio Project: `proj_set(rstudioapi::getActiveProject())`
@jennybc jennybc requested a review from hadley Aug 6, 2018
@jennybc jennybc force-pushed the proj-sitrep branch from f8ad170 to 18a735d Aug 6, 2018
jennybc added 2 commits Aug 7, 2018
@hadley
hadley approved these changes Aug 8, 2018
NEWS.md Outdated
@@ -1,5 +1,7 @@
# usethis 1.3.0.9000

* `proj_sitrep()` is a new function that reports current working directory, the active usethis project, and the active RStudio Project. The print method offers advice in situations that seem suboptimal (#426).

This comment has been minimized.

@hadley

hadley Aug 8, 2018
Member

Call this function if something seems wacky but you don't know what.

R/sitrep.R Outdated
format.sitrep <- function(x, ...) {
max_width <- max(nchar(names(x)))
format_string <- glue::glue("%{max_width}s")
padded_names <- sprintf(format_string, names(x))

This comment has been minimized.

@hadley

hadley Aug 8, 2018
Member

I think this could just be format(names(x))

R/sitrep.R Outdated
active_usethis_proj = if (proj_active()) proj_get() else NULL,
active_rstudio_proj = if (rstudioapi::hasFun("getActiveProject")) {
rstudioapi::getActiveProject()
} else NULL

This comment has been minimized.

@hadley

hadley Aug 8, 2018
Member

You can drop the else NULL; that's the default value of the else block.

jennybc added 3 commits Aug 8, 2018
# Conflicts:
#	NEWS.md
@jennybc jennybc merged commit c86aaa2 into master Aug 8, 2018
3 of 6 checks passed
3 of 6 checks passed
codecov/patch 16.98% of diff hit (target 62.15%)
Details
codecov/project 60.77% (-1.38%) compared to bc82105
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@jennybc jennybc deleted the proj-sitrep branch Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants