Created
October 26, 2023 23:42
-
-
Save mbjones/7defd8e6e9c9fe8da5084ceb4f20536c to your computer and use it in GitHub Desktop.
KNB download CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dataone) | |
# Download a CSV-formatted data file from the KNB | |
# repository, and convert it to a data.frame | |
get_dataframe <- function(pid) { | |
d1c <- D1Client("PROD", "urn:node:KNB") | |
data_raw <- getObject(d1c@mn, pid) | |
data_char <- rawToChar(data_raw) | |
csv_text <- textConnection(data_char) | |
df <- read.csv(csv_text, stringsAsFactors = FALSE) | |
return(df) | |
} | |
# data_url <- "https://knb.ecoinformatics.org/knb/d1/mn/v2/object/urn%3Auuid%3A4c9bdb65-e58b-41bc-8f80-10f59ee332e9" | |
# be sure to set your DataONE auth token first (but don't check it into scripts) for access to private data | |
# options(dataone_token = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIi...........lZNw") | |
pid <- "urn:uuid:4c9bdb65-e58b-41bc-8f80-10f59ee332e9" | |
df <- get_dataframe(pid) | |
head(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment