我在Windows上创建了一个指向RDS文件的快捷方式。有没有办法阅读'快捷方式并加载文件?
我已经尝试了以下命令,但失败了。
readRDS("...") # with correct location
答案 0 :(得分:2)
您可以使用R.Utils
包,它是readWindowsShortcut
功能 - > CRAN link
这是一个两步程序,其中:
readWindowsShortcut()
将.lnk
文件转换为列表readRDS
一个从列表中提取relativePath
元素以下是一个分步说明的工作示例:
data <- data.frame(a = c(1,2,3,4),
b = c("a", "b", "c", "d"))
# Save to disk (in working directory)
saveRDS(data, file = "data.Rds")
##
# Create a windows link `.lnk` manally
##
# Load (install if necessary) library
library(R.utils)
# Read content of .lnk and store it to an object
path <- readWindowsShortcut("data.Rds - Shortcut.lnk")
# See what's inside `path` object
summary(path)
Length Class Mode
header 12 -none- list
fileLocationInfo 4 -none- list
relativePath 1 -none- character
workingDirectory 1 -none- character
relativePathname 1 -none- character
pathname 1 -none- character
# Read RDS from `relativePath`
readRDS(path$relativePath)
a b
1 1 a
2 2 b
3 3 c
4 4 d