我试着从这条道路上加载并绘制一幅图片:
C:\Users\Rayane_2\Desktop\Data\PCB-DATASET-master\PCB-DATASET-master\01_missing_hole_01.jpeg我试过:
library(imager)
file <- system.file('C:\Users\Rayane_2\Desktop\Data\PCB-DATASET-master\PCB-DATASET-master\01_missing_hole_01.jpeg',package='imager')
im <- load.image(file)
im # file not found包提供的正确运行示例:
library(imager)
file <- system.file('extdata/parrots.png',package='imager')
#system.file gives the full path for a file that ships with a R package
#if you already have the full path to the file you want to load just run:
#im <- load.image("/somedirectory/myfile.png")
im <- load.image(file)
plot(im) #Parrots!谢谢你的帮助!
发布于 2021-12-27 15:17:49
错误:'\U‘在字符串中使用,没有十六进制数字,开头是“C:\U”
用另一个反斜杠转义它,如
'C:\Users\Rayane_2\Desktop\Data\PCB-DATASET-master\PCB-DATASET-master\01_missing_hole_01.jpeg‘
但是,即使在windows上,也可以使用正斜杠,所以这也是有效的:
'C:/Users/Rayane_2/Desktop/Data/PCB-DATASET-master/PCB-DATASET-master/01_missing_hole_01.jpeg'
system.file只在包中找到文件。来自?system.file:描述查找包等参数中文件的完整文件名.:字符向量,指定包中的子目录和文件。默认的none返回包的根。不支持通配符。
这意味着...参数中提供的所有路径都必须是相对的。其中一个例子就是你在问题中提出了什么,
system.file('extdata/parrots.png',package='imager')
如果您查看安装的包(可能是C:/Users/Rayane_2/R/win_library/4.1/imager)的文件结构,您将看到名为Meta、R、data、doc、help、html和(并不是每个包中都有) extdata的目录。该目录中必须是parrots.png。如果在指定包的安装目录中找到文件,则返回所查找文件的完整(绝对)路径。
system.file的值是您可能不知道完整的路径。当(1)在其他用户将使用您的代码进行编程操作时,这是一个很好的方法;(2)您在.libPaths()中有多个库路径,并且不知道哪个库路径包含包,并且不想自己检查它们;或者(3)您需要更短和更自文档化的代码。
如果您已经知道了文件的完整路径,那么system.file不会有帮助。
说到底,system.file是错误的函数。
库(成像仪) im <- load.image('C:/Users/Rayane_2/Desktop/Data/PCB-DATASET-master/PCB-DATASET-master/01_missing_hole_01.jpeg')
发布于 2021-12-27 15:32:10
用这个。
有关更多信息,请参见?Quotes、?file.path、?Sys.getenv、?path.expand。path.expand示例将取决于您的主目录是如何设置的,但通常它已经设置为C:\Users\yourname\Documents。
file.path("C:", "Users", "Rayane_2", "Desktop", "Data", "PCB-DATASET-master",
"PCB-DATASET-master", "01_missing_hole_01.jpeg")
file.path(Sys.getenv("USERPROFILE"), "Desktop", "Data", "PCB-DATASET-master",
"PCB-DATASET-master", "01_missing_hole_01.jpeg")
r"{C:\Users\Rayane_2\Desktop\Data\PCB-DATASET-master\PCB-DATASET-master\01_missing_hole_01.jpeg}"
"C:\\Users\\Rayane_2\\Desktop\\Data\\PCB-DATASET-master\\PCB-DATASET-master\\01_missing_hole_01.jpeg"
# this depends on how your home variable has been set but the
# setting is often such that this works
path.expand("~\\..\\Desktop\\Data\\PCB-DATASET-master\\PCB-DATASET-master\\01_missing_hole_01.jpeg")
"C:/Users/Rayane_2/Desktop/Data/PCB-DATASET-master/PCB-DATASET-master/01_missing_hole_01.jpeg"
# after entering this navigate to file. This will display the path
# to the file and you can then copy and paste it from the
# R console into your code.
file.choose()https://stackoverflow.com/questions/70497009
复制相似问题