簡體   English   中英

使用dir.create的“無法更改工作目錄”錯誤

[英]“cannot change working directory” error using dir.create

我已經使用dir.create創建了一組嵌套文件夾,但是現在無法將工作目錄設置為其中的任何一個。

我檢查了要更改的目錄的拼寫,這是正確的。 它存在。 我可以將文件移入其中並保存其中的文件。

我不知道發生了什么。 非常生氣。

有想法嗎?

sessionInfo()的輸出

R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  
LC_CTYPE=English_UnitedStates.1252 
LC_MONETARY=English_UnitedStates.1252 
LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_2.1.0 reshape_0.8.5 r4ss_1.24.0  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.3        lattice_0.20-33    corpcor_1.6.8
gtools_3.5.0       bitops_1.0-6       grid_3.2.3
plyr_1.8.3         gtable_0.2.0      
 [9] scales_0.4.0       coda_0.18-1        KernSmooth_2.23-15
gplots_2.17.0      gdata_2.17.0       tools_3.2.3
pso_1.0.3          munsell_0.4.3     
[17] maps_3.0.2         colorspace_1.2-6   caTools_1.17.1
tcltk_3.2.3       

補充說,這可行:

dir.create("new_dir")
list.files(pattern = "new_dir")
[1] "new_dir"
setwd("new_dir")

這是產生錯誤的完整代碼。

#set working directory
setwd("C:/Users/elizabeth.councill/Desktop/Projects/Rsimulator_recdevs
/SIMS/BR/")

dir_current = getwd()

#Create directories; Do not repeat these lines if the directories 
already exist. Modify filenames as appropriate
dir.create("lognormal-lognormal/")
dir.create("gamma-lognormal/")
dir.create("lognormal-gamma/")
dir.create("gamma-gamma/")

#Create simulation directories and copy source files to each of them.
filestocopy <- c("source/BLK_WA_ctl.ss",
                 "source/BLK_WA_dat.ss",
                 "source/forecast.ss",
                 "source/ss3.exe",
             "source/starter.ss")

# Create sequence of folder names to make compact loop.
SEQ_sims <- c("lognormal-lognormal/","gamma-lognormal/","lognormal-
gamma/","gamma-gamma/")

# Create directories and move original source files over.
for (i in seq_along(SEQ_sims))
{
  for (j in 1:N)
  {
  dir.create(paste(SEQ_sims[i],j))
  file.copy(from = filestocopy,to=paste(SEQ_sims[i],j))
  }
}
setwd("C:/Users/elizabeth.councill/Desktop/Projects/Rsimulator_recdevs
/SIMS/BR/lognormal-lognormal/1")

Error in setwd("C:/Users/elizabeth.councill/Desktop/Projects
  /Rsimulator_recdevs/SIMS/BR/lognormal-lognormal/1") : 
  cannot change working directory

嘗試setwd("./new_dir")

  dir.create(file.path(mainDir, subDir), showWarnings = FALSE)
  setwd(file.path(mainDir, subDir))

使用showWarnings = FALSEmainDir是主目錄, subDir是您創建的子目錄。 使用showWarnings = FALSE時要小心,因為這也會隱藏其他警告,例如未創建目錄。

 # Example:
 dir.create("SSSSS")
 dir.create("./SSSSS/xxyyzz")
 setwd("./SSSSS/xxyyzz")
 getwd()
 [1] "C:/Users/Asus/Documents/SSSSS/xxyyzz"
 sessionInfo()
 R version 3.2.3 (2015-12-10)
 Platform: x86_64-w64-mingw32/x64 (64-bit)
 Running under: Windows 10 x64 (build 10586)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM