在RMarkdown中,我已经设置了根目录和控制台工作目录,但无法从正确的目录导入read.pnm。这就是我所拥有的:
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir = "C:/Users/customdir/.../folder")
library(pixmap)getwd()
img = read.pnm("~/folder2/img.pgm")从getwd()的输出中,我可以看出它在正确的目录中,但是我得到了错误:
Warning in file(file, open = "rb") :
cannot open file 'C:/Users/user/Documents/folder2/img.pgm': No such file or directory
Error in file(file, open = "rb") : cannot open the connection我不知道它为什么要在"C:/Users/user/Documents/"中查找,因为这不是我指定的目录。
还有其他需要更改的目录吗?
发布于 2022-03-05 00:28:06
文件名的"~“部分指向您的个人主目录(不是当前的工作目录)。当您使用"~“时,您将给出一个绝对路径,而不是相对于您的工作目录的路径。如果要在当前工作目录中找到该文件,请使用
img = read.pnm("folder2/img.pgm")https://stackoverflow.com/questions/71357804
复制相似问题