【问题标题】:R fails to save files in the current working directoryR无法将文件保存在当前工作目录中
【发布时间】:2018-03-17 20:20:12
【问题描述】:

我的文件未能保存在R中正确的目录。例如,我的工作目录是/folder/subfolder,但是当我保存文件时,它们都保存在/folder中。当我使用getwd 或将setwd 重置为subfolder 时,R 显示我在我想要的那个(/folder/subfolder)中。有人知道为什么吗?

我正在 Mac OS 上保存绘图和模型输出:

setwd("/folder/subfolder")

getwd()
"/folder/subfolder"

list.files()
"group.jpg"                   
"Stake.htm"

stargazer(model, out = "sampleOutput")
jpeg("sample.jpg")
plot(sample, horiz = F)
dev.off()

list.file()
"group.jpg"                   
"Stake.htm"

谢谢!

【问题讨论】:

  • 您如何尝试保存文件? CSV、RData 还是 RDS?您使用的是什么操作系统?
  • @JonGrub 感谢您的提醒,我已经更新了我的问题。
  • 您能否编辑您的问题以在尝试保存之前显示getwd()list.files() 之后的结果?
  • 顺便说一句,stargazer 有一个 out 参数但没有 output 参数...
  • @BenBolker thx,一个错字。

标签: r directory save


【解决方案1】:

你可以试试 jpeg("/subfolder/sample.jpg") 吗?这应该强制 R 保存到子文件夹。

【讨论】:

  • 我试过了,但是有错误No such file or directoryError in file(file, ifelse(append, "a", "w")) : cannot open the connection
  • 您可以在这里尝试 Maurice Reeves 的回答中推荐的东西:stackoverflow.com/questions/17156445/… 吗?您可能需要以管理员身份运行 R 才能使该命令正常工作 (?)。
猜你喜欢
  • 2022-01-21
  • 1970-01-01
  • 2014-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-16
  • 1970-01-01
  • 2016-09-13
相关资源
最近更新 更多