# Digests (deep) nested lists from Genesys
# N. Castaneda
# 2018-06-11
require(devtools)
require(tidyverse)
devtools::install_git('https://gitlab.croptrust.org/genesys-pgr/genesysr')
require(genesysr)
# or sandbox.genesys-pgr.org
genesysr::setup_sandbox()
# Open Genesys web page in browser and get verifier code
genesysr::user_login()
# Query genesys
filters <- mcpd_filter(ORIGCTY = c("DEU", "SVN")) #filter by ORIGCTY
accessions <- genesysr::fetch_accessions(filters)
filters <- jsonlite::fromJSON('{"geo.latitude":[{"range":[-180,180]}]}') #filter all records with geo.latitude
accessions <- genesysr::fetch_accessions(filters)
# Exploring the query
class(accessions)
head(accessions)
accessions$content
names(accessions$content[[1]])
# Flattening the query
gen.data <- lapply(accessions$content, unlist) #looks good
gen.data <- gen.data %>% map_df(bind_rows)