gpt4 book ai didi

r - 在 R 中使用 setwd() 返回默认值

转载 作者:行者123 更新时间:2023-12-01 10:51:07 24 4
gpt4 key购买 nike

有谁知道返回 R 中默认工作目录的简单方法?

我知道我可以输入我的家庭路径...

setwd("C:/Users/me/Desktop")

...但我想我很懒惰。是否有默认命令或诸如...
setwd(default)?

如果你知道这个问题的答案,谢谢。

保罗

最佳答案

这是一个替代解决方案,因为 Defaults包已归档:

# 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")

或者你可以屏蔽 base::setwd()有类似的东西:
setwd <- function(dir) {
if (missing(dir) || is.null(dir) || dir == "") {
dir <- "C:/Users/me/Desktop"
}
base::setwd(dir)
}

更新: Defaults 包已存档,因此此解决方案仅在您从 CRAN 存档下载包并自己从源代码构建时才有效。

您可以使用 Defaults包将其设置为您想要的。然后你可以调用 setwd() .
library(Defaults)
setDefaults(setwd, dir="C:/Users/me/Desktop")
setwd()

this answer if you want to put the above code in your .Rprofile .

关于r - 在 R 中使用 setwd() 返回默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20107634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com