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

here::u_r() #78

Open
beevabeeva opened this issue Dec 11, 2021 · 0 comments
Open

here::u_r() #78

beevabeeva opened this issue Dec 11, 2021 · 0 comments

Comments

@beevabeeva
Copy link

First of all, thank you to @krlmlr et al. for this great package. I use it daily.

I have made a pull request for a new function here::u_r (see #77).

Not sure if the contributors prefer to discuss/review it in an issue or in the comments for the PR, so I opened both 😅 .

I was inspired to submit the PR after keeping (and using) this function locally for a while, but later reading #41, #28 and #19 (and @krlmlr 's replies to them).

here::u_r()

#' 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()){
        library(here)
    }
    setwd(target_wd)
    library(here)
}
@beevabeeva beevabeeva changed the title here::u_r() here::u_r() Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant