Storing R Objects in a relational database

前端 未结 5 2050
鱼传尺愫
鱼传尺愫 2020-12-07 19:26

I frequently create nonparametric statistics (loess, kernel densities, etc) on data I pull out of a relational database. To make data management easier I would like to store

5条回答
  •  粉色の甜心
    2020-12-07 20:00

    Using textConnection / saveRDS / loadRDS is perhaps the most versatile and high level:

    zz<-textConnection('tempConnection', 'wb')
    saveRDS(myData, zz, ascii = T)
    TEXT<-paste(textConnectionValue(zz), collapse='\n')
    
    #write TEXT into SQL
    ...
    closeAllConnections()  #if the connection persists, new data will be appended
    
    #reading back:
    #1. pull from SQL into queryResult
    ...
    #2. recover the object
    recoveredData <- readRDS(textConnection(queryResult$TEXT))
    

提交回复
热议问题