Here is an alternative solution, since the Defaults
package has been archived:
# Use `formals<-`, but note the comment in the examples of ?formals:
#
## You can overwrite the formal arguments of a function (though this is
## advanced, dangerous coding).
formals(setwd) <- alist(dir = "C:/Users/me/Desktop")
Or you could mask base::setwd()
with something like:
setwd <- function(dir) {
if (missing(dir) || is.null(dir) || dir == "") {
dir <- "C:/Users/me/Desktop"
}
base::setwd(dir)
}
UPDATE: The Defaults package has been archived, so this solution only works if you download the package from the CRAN archive and build from source yourself.
You could use the Defaults package to set it to what you want. Then you could just call setwd()
.
library(Defaults)
setDefaults(setwd, dir="C:/Users/me/Desktop")
setwd()
See this answer if you want to put the above code in your .Rprofile.