在R中读取键值文件

Mad*_*Seb 2 r file

有没有办法在R中读取一个简单的文本键值文件...

Key1=Value1
Key2=Value2
Key3=Value3
Run Code Online (Sandbox Code Playgroud)

理想情况下,我想访问这样的数据:

myfile $ Key1应该返回Value1,myfile @ Key2应该返回Value2
,依此类推

干杯! MadSeb

PS我查看了stashR和filehash包,虽然这些包实现了很好的键值数据库,但它们并不以简单/可读的文本格式存储数据库.

dig*_*All 5

这样的事情怎么样:

dframe <- read.table(file='yourfile.txt',header=FALSE,
                     sep='=',col.names=c('Key','Value'))
Run Code Online (Sandbox Code Playgroud)

那么,如果你想通过密钥更快地访问,你可以使用data.table,例如:

library(data.table)
dframe <- read.table(file='yourfile.txt',header=FALSE,
                     sep='=',col.names=c('Key','Value'))
dtable <- data.table(dtfrm,key='Key')

dtable['Key1']
Run Code Online (Sandbox Code Playgroud)