【发布时间】:2022-01-26 12:12:34
【问题描述】:
我正在尝试从该路径加载和绘制图片:
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!
感谢您的帮助!
【问题讨论】:
-
(1) 目录反斜杠(windows)必须总是转义,所以
"C:\\Users\\Rayane_2\\..."。不过,即使在 Windows 上,您也可以像"C:/Users/Rayane_2/..."中那样使用正斜杠,但许多人发现双反斜杠在视觉上令人不快。 (2)system.file查找包内的文件,一般不查找。任何包中都没有名为"C:\\Users\\...\\01_missing_hole_01.jpg"的文件。要么使用load.image("C:\\Users\\...\01_missing_hole_01.jpg")。 -
来自
?system.file,该函数旨在查找“包中文件的完整文件名”。 -
我需要从桌面找到的文件目录加载
-
看我的回答。底线,停止使用
system.file,这是任务的错误功能。
标签: r image-processing