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

added new function here::u_r #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export(dr_here)
export(here)
export(i_am)
export(set_here)
export(u_r)
import(rprojroot)
49 changes: 49 additions & 0 deletions R/u_r.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#' Resets here() root to current or target working directory.
#'
#' If no target root directory is specified, the current working directory will be used.
#' There is no need to restart the session
#'
#' The function is named:
#' u_r (as in "here::you_are") in reference to:
#' 1. everyone:'WHY ISN"T THIS INCLUDED IN THE PACKAGE!?'
#' me: 'Well, here you are.'
#'
#' 2. user:'Start here() at my cwd.'
#' here:'OK, here you are.' (anastrophe)
#'
#' u_r (as in "here::user_reset") in reference to:
#' 1. Providing a quick way for a user to reset the root of here().
#'
#' u_r (as in "here::unload_reload") in reference to:
#' 1. The method used to change the root of here().
#'
#' Q: Why use this when there's RStudio projects?
#' A: There are certain cases where this method is preferable.
#'
#'
#' @param target_wd `[character(1)]`\cr
#' The target root directory to start here() from.
#' If no target root directory is specified,
#' the current working directory will be used.
#'
#' @export
#' @examples
#' \dontrun{
#' setwd("/somewhere") # initial working directory.
#' here() # 'here starts at /somewhere/'
#' setwd("/anywhere/else") # change working directory
#' here::u_r() # 'here starts at /anywhere/else'
#'
#' setwd("/somewhere/") # initial working directory.
#' here() # 'here starts at /somewhere/'
#' here::u_r("/anywhere/else") # 'here starts at /anywhere/else'
#' getwd() # "/anywhere/else"
#' }
u_r <- function(target_wd=getwd()){
detach("package:here", unload=TRUE)
if(target_wd==getwd()){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if is unnecessary? setwd(getwd()) is a no-op and doesn't need to be guarded against?

library(here)
}
setwd(target_wd)
library(here)
}
48 changes: 48 additions & 0 deletions man/u_r.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.