diff --git a/NAMESPACE b/NAMESPACE index f31f993..ff70bd5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,4 +4,5 @@ export(dr_here) export(here) export(i_am) export(set_here) +export(u_r) import(rprojroot) diff --git a/R/u_r.R b/R/u_r.R new file mode 100644 index 0000000..60899bf --- /dev/null +++ b/R/u_r.R @@ -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()){ + library(here) + } + setwd(target_wd) + library(here) +} \ No newline at end of file diff --git a/man/u_r.Rd b/man/u_r.Rd new file mode 100644 index 0000000..f6c556a --- /dev/null +++ b/man/u_r.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/u_r.R +\name{u_r} +\alias{u_r} +\title{Resets here() root to current or target working directory.} +\usage{ +u_r(target_wd = getwd()) +} +\arguments{ +\item{target_wd}{\verb{[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.} +} +\description{ +If no target root directory is specified, the current working directory will be used. +There is no need to restart the session +} +\details{ +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.'\preformatted{ 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. +} +\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" +} +}