hook_output <- knitr::knit_hooks$get("output") knitr::knit_hooks$set(output = function(x, options) { lines <- options$output.lines if (is.null(lines)) { return(hook_output(x, options)) # pass to default hook } x <- unlist(strsplit(x, "\n")) more <- "..." if (length(lines) == 1) { # first n lines if (length(x) > lines) { # truncate the output, but add .... x <- c(head(x, lines), more) } } else { x <- c(if (abs(lines[1])>1) more else NULL, x[lines], if (length(x)>lines[abs(length(lines))]) more else NULL ) } # paste these lines together x <- paste(c(x, ""), collapse = "\n") hook_output(x, options) }) knitr::opts_chunk$set( warning = FALSE, message = FALSE, collapse = TRUE, comment = "#>" )
finch
parses Darwin Core simple and archive files
Docs: https://docs.ropensci.org/finch/
Stable version
install.packages("finch")
Development version, from GitHub
remotes::install_github("ropensci/finch")
library("finch")
To parse a simple darwin core file like
<?xml version="1.0" encoding="UTF-8"?> <SimpleDarwinRecordSet xmlns="http://rs.tdwg.org/dwc/xsd/simpledarwincore/" xmlns:dc="http://purl.org/dc/terms/" xmlns:dwc="http://rs.tdwg.org/dwc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://rs.tdwg.org/dwc/xsd/simpledarwincore/ ../../xsd/tdwg_dwc_simple.xsd"> <SimpleDarwinRecord> <dwc:occurrenceID>urn:catalog:YPM:VP.057488</dwc:occurrenceID> <dc:type>PhysicalObject</dc:type> <dc:modified>2009-02-12T12:43:31</dc:modified> <dc:language>en</dc:language> <dwc:basisOfRecord>FossilSpecimen</dwc:basisOfRecord> <dwc:institutionCode>YPM</dwc:institutionCode> <dwc:collectionCode>VP</dwc:collectionCode> <dwc:catalogNumber>VP.057488</dwc:catalogNumber> <dwc:individualCount>1</dwc:individualCount> <dwc:locationID xsi:nil="true"/> <dwc:continent>North America</dwc:continent> <dwc:country>United States</dwc:country> <dwc:countryCode>US</dwc:countryCode> <dwc:stateProvince>Montana</dwc:stateProvince> <dwc:county>Garfield</dwc:county> <dwc:scientificName>Tyrannosourus rex</dwc:scientificName> <dwc:genus>Tyrannosourus</dwc:genus> <dwc:specificEpithet>rex</dwc:specificEpithet> <dwc:earliestPeriodOrHighestSystem>Creataceous</dwc:earliestPeriodOrHighestSystem> <dwc:latestPeriodOrHighestSystem>Creataceous</dwc:latestPeriodOrHighestSystem> <dwc:earliestEonOrHighestEonothem>Late Cretaceous</dwc:earliestEonOrHighestEonothem> <dwc:latestEonOrHighestEonothem>Late Cretaceous</dwc:latestEonOrHighestEonothem> </SimpleDarwinRecord> </SimpleDarwinRecordSet>
This file is in this package as an example file, get the file, then simple()
file <- system.file("examples", "example_simple_fossil.xml", package = "finch") out <- simple_read(file)
Index to meta
, dc
or dwc
out$dc
To parse a Darwin Core Archive like can be gotten from GBIF use dwca_read()
There's an example Darwin Core Archive:
file <- system.file("examples", "0000154-150116162929234.zip", package = "finch") (out <- dwca_read(file, read = TRUE))
List files in the archive
out$files
High level metadata for the whole archive
out$emlmeta
High level metadata for each data file, there's many files, but we'll just look at one
hm <- out$highmeta head( hm$occurrence.txt )
You can get the same metadata as above for each dataset that went into the tabular dataset downloaded
out$dataset_meta[[1]]
View one of the datasets, brief overview.
head( out$data[[1]][,c(1:5)] )
You can also give dwca()
a local directory, or url that contains a Darwin Core Archive.
finch
in R doing citation(package = 'finch')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.