R- 将工作目录设置为 hdfs

R- set working directory to hdfs

我需要在 R 中从非常大的数据集中创建一些数据框。有没有办法更改我的工作目录,以便将我创建的 R 对象保存到 hdfs 中?我在 /home 下没有足够的 space 来保存这些大数据框,但是我需要使用一些需要数据框作为输入的数据框函数。

如果我们使用数据帧对来自 hdfs 的数据进行一些操作,我们在技术上使用的是内存而不是磁盘 space。因此,限制因素将是内存 (RAM),而不是任何工作目录中的可用磁盘 space,并且更改工作目录没有太大意义。

您无需将文件从 hdfs 复制到本地计算上下文即可将其作为数据帧进行处理。

使用 rxReadXdf() 直接将 xdf 数据集转换为 hdfs 本身的数据帧。

类似这样的事情(假设您在 hadoop 计算上下文中):

airDS <- RxTextData(file="/data/revor/AirlineDemoSmall.csv", fileSystem=hdfFS)
# making a text data source from a csv file at above hdfs location 
# hdfsFS is the object storing hadoop fileSystem details using RxHdfsFileSyStem() 

airxdf <- RxXdfData(file= "/data/AirlineXdf")
# specifying the location to create the composite xdf file in hdfs
# make sure this location exits in hdfs


airXDF <- rxImport(inFile=airDS, outFile=airxdf)
# Importing csv to composite xdf 


airDataFrame <- rxReadXdf(file=airXDF)

# Now airDataFrame is a dataframe in memory 
# use class(airDataframe) to double check
# do your required operations on this data frame