在 Rstudio 中创建新项目将它放在 ~ / This PC / Documents 文件夹中,而不是在全局选项中指定的目录和
Creating new Project in Rstuido puts it in ~ / This PC / Documents folder instead of directory specified in Global Options and
我刚开始在 Coursera 上学习 R。
安装 RStudio 后,我创建了这个目录来保存我创建的新项目:C:/dev/r
- 我在全局选项/默认工作目录中输入了这个目录路径(见下文)
- 但是,当我使用 Coursera 中的说明创建一个新的 R 项目时(见下文),它有一个选项“将项目创建为 ~ 的子目录”
- 如果我只输入项目名称并单击“创建项目”,它会将其创建为“This PC / Documents”的子目录
- 我可以明确地将“~”替换为“C:/dev/r”,它会在正确的位置创建项目文件夹,但我不想每次创建项目时都必须这样做项目
- 本质上,我可以“告诉”RStudio ~ =“c:/dev/r”,而不是“This PC / Documents”吗?
项目创建成功,但是创建的目录是C:\Users{我的Windows用户名}\Documents\MyProject
这是我的 .RHistory
getwd()
setwd("C:/dev/r")
dir
cd
?Startup
R_CHECK_ENVIRON
R_CHECK_ENVIRON()
candidates <- c( Sys.getenv("R_PROFILE"),
file.path(Sys.getenv("R_HOME"), "etc", "Rprofile.site"),
Sys.getenv("R_PROFILE_USER"),
file.path(getwd(), ".Rprofile") )
Filter(file.exists, candidates)
file.path(Sys.getenv("HOME"), ".Rprofile")
setwd("C:/dev/r")
getwd()
getwd()
getwd()
getwd()
install.packages("ggplot2")
这是我的 Rprofile.site:
# Things you might want to change
# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")
# set the default help type
# options(help_type="text")
options(help_type="html")
# set a site library
# .Library.site <- file.path(chartr("\", "/", R.home()), "site-library")
# set a CRAN mirror
# local({r <- getOption("repos")
# r["CRAN"] <- "http://my.local.cran"
# options(repos=r)})
# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
# if (interactive())
# fortunes::fortune()
setwd("C:/dev/r")
我会说这是因为 create project as a subdirectory of
被指定为 ~
而不是您的工作目录。 ~
用于指定大多数系统上的主(用户)目录。如果您在创建时更改设置,使其指向您的 working directory
,那么您应该没有任何问题
~
的位置设置自(在 Windows 上):Sys.getenv("USERNAME")
请参阅:https://support.rstudio.com/hc/en-us/articles/201751487-Sharing-a-Project-with-multiple-users。由于还有一个 Sys.setenv
函数,您可以通过调整该环境变量来实现您的目标。
我刚开始在 Coursera 上学习 R。
安装 RStudio 后,我创建了这个目录来保存我创建的新项目:C:/dev/r
- 我在全局选项/默认工作目录中输入了这个目录路径(见下文)
- 但是,当我使用 Coursera 中的说明创建一个新的 R 项目时(见下文),它有一个选项“将项目创建为 ~ 的子目录”
- 如果我只输入项目名称并单击“创建项目”,它会将其创建为“This PC / Documents”的子目录
- 我可以明确地将“~”替换为“C:/dev/r”,它会在正确的位置创建项目文件夹,但我不想每次创建项目时都必须这样做项目
- 本质上,我可以“告诉”RStudio ~ =“c:/dev/r”,而不是“This PC / Documents”吗?
项目创建成功,但是创建的目录是C:\Users{我的Windows用户名}\Documents\MyProject
这是我的 .RHistory
getwd()
setwd("C:/dev/r")
dir
cd
?Startup
R_CHECK_ENVIRON
R_CHECK_ENVIRON()
candidates <- c( Sys.getenv("R_PROFILE"),
file.path(Sys.getenv("R_HOME"), "etc", "Rprofile.site"),
Sys.getenv("R_PROFILE_USER"),
file.path(getwd(), ".Rprofile") )
Filter(file.exists, candidates)
file.path(Sys.getenv("HOME"), ".Rprofile")
setwd("C:/dev/r")
getwd()
getwd()
getwd()
getwd()
install.packages("ggplot2")
这是我的 Rprofile.site:
# Things you might want to change
# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")
# set the default help type
# options(help_type="text")
options(help_type="html")
# set a site library
# .Library.site <- file.path(chartr("\", "/", R.home()), "site-library")
# set a CRAN mirror
# local({r <- getOption("repos")
# r["CRAN"] <- "http://my.local.cran"
# options(repos=r)})
# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
# if (interactive())
# fortunes::fortune()
setwd("C:/dev/r")
我会说这是因为 create project as a subdirectory of
被指定为 ~
而不是您的工作目录。 ~
用于指定大多数系统上的主(用户)目录。如果您在创建时更改设置,使其指向您的 working directory
,那么您应该没有任何问题
~
的位置设置自(在 Windows 上):Sys.getenv("USERNAME")
请参阅:https://support.rstudio.com/hc/en-us/articles/201751487-Sharing-a-Project-with-multiple-users。由于还有一个 Sys.setenv
函数,您可以通过调整该环境变量来实现您的目标。