Task: Connect to the DataONE production environment, retrieve the list of Objects, and print out the list.
First, load the dataone
R package and connect to the production Coordinating Node:
library(dataone)
cn <- CNode()
listObjects
accepts a number of optional arguments (see ?listObjects
) such as count
which controls the number of objects that are returned:
listObjects(cn, count = 5)
As another example, we can filter to just CSV objects created within a time frame:
csvs <- listObjects(cn,
fromDate = "2020-01-01T00:00:00.000Z",
toDate = "2021-01-01T00:00:00.000Z",
formatId = "text/csv",
count = 5)
length(csvs$objectInfo)
You can see we received five results like we requested but there are many more available:
csvs$.attrs[3]
Knowing this, we can use the start
argument to page through the results:
page_two <- listObjects(cn,
fromDate = "2020-01-01T00:00:00.000Z",
toDate = "2021-01-01T00:00:00.000Z",
formatId = "text/csv",
count = 5,
start = 5)
page_two