R 通过快捷方式读取 RDS 文件



我在Windows上创建了一个指向RDS文件的快捷方式。有没有办法"读取"快捷方式并加载文件?

我尝试了以下命令,但失败了。

readRDS("...")  # with correct location
您可以使用

R.Utils包,它是readWindowsShortcut函数 -> CRAN 链接

这是一个两步过程,其中:

  1. 使用 readWindowsShortcut().lnk文件转换为列表
  2. 使用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

最新更新