Comment #2 on issue 58 by
iand...@gmail.com: RPostgreSQL does not have
One option would have JSON converted to text. Not sure whether it makes a
difference having RPostgreSQL do this versus doing it by an explicit cast
to text in PostgreSQL (may matter more with the new [9.4] jsonb data type.
(PS. I've found the RJSONIO package to work nicely with JSON returned as
text. The function `word_count` below is a PL/Python function that accepts
text and returns JSON derived from a Python dictionary.
library(RPostgreSQL)
pg <- dbConnect(PostgreSQL())
# Get count data. Data is JSON converted to text.
count_raw <- dbGetQuery(pg, "
SELECT key_id, word_count(some_text)::text AS word_counts
FROM some_table")
# Convert JSON-as-text to records where each key becomes a column
require(RJSONIO)
count_data <- as.data.frame(do.call(rbind,
lapply(count_raw$word_counts,
fromJSON)))
# Combine converted JSON data with key field
count_data <- cbind(count_raw$key_id, count_data)
)