NEON tutorial help

Hi! I'm going through the NEON API in R tutorial and cannot figure out why this code is not working. It is literally a copy of the tutorial code. When I run it it works up until # get data availability from location/date of interest. At which point when I try to create the tmp object I receive this error:

Error in parse_url(url) : length(url) == 1 is not TRUE

I can't find anything useful online about this. Any help appreciated.

##Packages##
library(httr)
library(jsonlite)
library(devtools)
library(dplyr, quietly = T)
library(downloader)
library(geoNEON)
library(neonUtilities)

##Requests Data##
req <- GET("http://data.neonscience.org/api/v0/products/DP1.10003.001")
req

##View requested data##
req.content <- content(req, as="parsed")
names(req.content$data)

##View abstract##
req.content$data$productAbstract

## View Available months and associated URLs for Onaqui, Utah - ONAQ ##
req.content$data$siteCodes[[27]]

## make this JSON readable -> "text" ##
req.text <- content(req, as="text")

## Flatten data frame to see available data. ##
avail <- jsonlite::fromJSON(req.text, simplifyDataFrame=T, flatten=T)
avail

## get data availability list for the product ##
bird.urls <- unlist(avail$data$siteCodes$availableDataUrls)
length(bird.urls) #total number of URLs

bird.urls[1:10] #show first 10 URLs available

## get data availability for WOOD July 2015 ##
brd <- GET(bird.urls[grep("WOOD/2015-07", bird.urls)])
brd.files <- jsonlite::fromJSON(content(brd, as="text"))

## view just the available data files ##
brd.files$data$files

## Get both files ##
brd.count <- read.delim(brd.files$data$files$url
                        [intersect(grep("countdata", 
                                        brd.files$data$files$name),
                                   grep("basic", 
                                        brd.files$data$files$name))], 
                        sep=",")

brd.point <- read.delim(brd.files$data$files$url
                        [intersect(grep("perpoint", 
                                        brd.files$data$files$name),
                                   grep("basic", 
                                        brd.files$data$files$name))], 
                        sep=",")

## Quick Graph ##
# Cluster by species 
clusterBySp <- brd.count %>%
  dplyr::group_by(scientificName) %>%
  dplyr::summarise(total=sum(clusterSize, na.rm=T))

# Reorder so list is ordered most to least abundance
clusterBySp <- clusterBySp[order(clusterBySp$total, decreasing=T),]

# Plot
barplot(clusterBySp$total, names.arg=clusterBySp$scientificName, 
        ylab="Total", cex.names=0.5, las=2)

##Instrumentation Data (IS)##
# Request soil temperature data availability info
req.soil <- GET("http://data.neonscience.org/api/v0/products/DP1.00041.001")

# make this JSON readable
# Note how we've change this from two commands into one here
avail.soil <- jsonlite::fromJSON(content(req.soil, as="text"), simplifyDataFrame=T, flatten=T)

# get data availability list for the product
temp.urls <- unlist(avail.soil$data$siteCodes$availableDataUrls)

# get data availability from location/date of interest
tmp <- GET(temp.urls[grep("MOAB/2017-03", temp.urls)])
tmp.files <- jsonlite::fromJSON(content(tmp, as="text"))
length(tmp.files$data$files$name) # There are a lot of available files

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.