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
Add function to report the State of the Project and Working Directory #426
Conversation
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:
|
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop the else NULL
; that's the default value of the else block.
# Conflicts: # NEWS.md
Objective: create a reporter or doctor function that reveals
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:
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.