在 Rstudio 中创建新项目将它放在 ~ / This PC / Documents 文件夹中,而不是在全局选项中指定的目录和

Creating new Project in Rstuido puts it in ~ / This PC / Documents folder instead of directory specified in Global Options and

项目创建成功,但是创建的目录是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 函数,您可以通过调整该环境变量来实现您的目标。