| Title: | USGS INL Project Office Publications |
|---|---|
| Description: | Provides bibliographic information and term-frequency text analysis tools for publications of the U.S. Geological Survey (USGS) Idaho National Laboratory (INL) Project Office. Includes datasets of publications, authors, and term frequencies, along with functions to search terms, build word clouds, and extract text and cover images from publication documents. |
| Authors: | Jason C. Fisher [aut, cre] (ORCID: <https://orcid.org/0000-0001-9032-8912>), Kerri C. Treinen [aut] (ORCID: <https://orcid.org/0000-0003-0645-6810>), Allison R. Trcka [aut] (ORCID: <https://orcid.org/0000-0001-8498-4737>) |
| Maintainer: | Jason C. Fisher <[email protected]> |
| License: | CC0 |
| Version: | 1.4.0 |
| Built: | 2026-10-04 09:37:32 UTC |
| Source: | https://github.com/cran/inlpubs |
Extract the text or cover image from publication PDF documents and
save the result to disk, for incorporation into the inlpubs package corpus.
Publications are selected by identifier or by year, and each must already be
present in the pubs dataset before this function is run.
add_content( pub_id, year, type = c("text", "image"), ..., srcdir = "archive", destdir = tempdir(), ignore = NULL, pubs = inlpubs::pubs, overwrite = FALSE )add_content( pub_id, year, type = c("text", "image"), ..., srcdir = "archive", destdir = tempdir(), ignore = NULL, pubs = inlpubs::pubs, overwrite = FALSE )
pub_id |
'character' vector.
Unique identifier(s) of the publication(s) to process.
Publications may instead, or additionally, be selected with |
year |
'integer' vector.
Year(s) of publication. All publications from the given year(s) are selected,
in addition to any specified by |
type |
'character' string.
Type of content to extract from each PDF, either |
... |
Additional arguments passed to the extraction function:
|
srcdir |
'character' string.
Source directory containing the publication PDFs, organized into
year subdirectories (see Details). Defaults to |
destdir |
'character' string. Destination directory for the extracted output files. Created if it does not already exist. Defaults to the session's temporary directory. |
ignore |
'character' vector. Publication identifier(s) to skip. Useful for documents that are known to fail automatic extraction. |
pubs |
'pub' table.
Publications of the INLPO; see the |
overwrite |
'logical' flag.
Whether to overwrite an existing output file. Defaults to |
For each selected publication, the function locates its primary PDF (the
first file listed in the publication's files entry) within the source directory,
then delegates extraction to get_pdf_text (for type = "text") or
get_pdf_image (for type = "image"). Extra arguments passed through ...
are forwarded to whichever of those functions is used.
Source documents are expected to follow the archive layout
srcdir/<year>/<pub_id>/<file>, for example
archive/2005/KnobelOthers2005/ofr20051223.pdf. Output files are written to
destdir and named pub-<pub_id>, with the appropriate extension (.txt or
.jpg) supplied by the extraction function.
Publications whose files entry is empty, and those listed in ignore, are
skipped with a message. By default, existing output files are left in place;
set overwrite = TRUE to regenerate them.
Extraction failures (including renderer crashes or timeouts on problematic
PDFs) are caught per publication: the offending document is reported and
skipped, and processing continues with the next one. The identifiers of any
failed documents are returned in the "failed" attribute of the result.
Processing the full archive can take a considerable amount of time. For routine use, run this function interactively and one publication year at a time so that progress can be monitored.
Invisibly returns a 'character' vector of paths to the saved output files,
carrying a "failed" attribute with the identifiers of any publications whose
extraction failed. Returns NULL (invisibly) when no publications remain to
process.
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
get_pdf_text and get_pdf_image for the underlying extraction
functions, and the pubs dataset for publication metadata.
## Not run: # Extract text for a single publication into the corpus folder add_content("KnobelOthers2005", destdir = "data-raw/corpus") # Extract text for every publication from a given year add_content(year = 2005, destdir = "data-raw/corpus") # Extract cover images into the vignettes folder add_content(year = 2005, type = "image", destdir = "vignettes") # Process several years, skipping a document that fails extraction add_content(year = 2003:2005, ignore = "Mazurek2004", destdir = "data-raw/corpus") ## End(Not run)## Not run: # Extract text for a single publication into the corpus folder add_content("KnobelOthers2005", destdir = "data-raw/corpus") # Extract text for every publication from a given year add_content(year = 2005, destdir = "data-raw/corpus") # Extract cover images into the vignettes folder add_content(year = 2005, type = "image", destdir = "vignettes") # Process several years, skipping a document that fails extraction add_content(year = 2003:2005, ignore = "Mazurek2004", destdir = "data-raw/corpus") ## End(Not run)
Authors who have contributed to publications by the U.S. Geological Survey (USGS), Idaho Water Science Center, Idaho National Laboratory Project Office (INLPO).
authorsauthors
An object of class 'author' that inherits from the 'data.frame' class and contains 267 rows and the following 10 columns:
author_idUnique identifier for the author, composed of the author's
first initial and last name in lowercase (for example, "jfisher").
nameAuthor name, surname first, followed by initials or given name.
personA named list of person objects holding
contact details such as email address and
ORCID identifier. Names match author_id.
pub_idA named list of character vectors giving the identifier(s) of
the publication(s) the author contributed to; each value is a foreign key
referencing the pub_id primary key of the pubs table.
total_pubTotal number of publications.
single_authoredNumber of single-authored publications.
multi_authoredNumber of multi-authored publications.
first_authoredNumber of multi-authored publications in which the author appears as the first author.
first_yearFirst year in which the author published.
last_yearMost recent year in which the author published.
Curated by INLPO staff.
pubs for the publications referenced by pub_id.
# Subset Jason Fisher's information and display its structure: author <- authors["jfisher", ] str(author, max.level = 3, width = 75, strict.width = "cut") # Print the author's given name: author$person |> format(include = "given")# Subset Jason Fisher's information and display its structure: author <- authors["jfisher", ] str(author, max.level = 3, width = 75, strict.width = "cut") # Print the author's given name: author$person |> format(include = "given")
Render a single page of a PDF document to a JPEG image. Typically used to capture a publication's cover (the first page) as a thumbnail. Requires that the pdftools, magick, and callr packages are available.
get_pdf_image( input, output = tempfile(fileext = ".jpg"), page = 1, width = 300, depth = 8, quality = 70, timeout = 120 )get_pdf_image( input, output = tempfile(fileext = ".jpg"), page = 1, width = 300, depth = 8, quality = 70, timeout = 120 )
input |
'character' string. File path to the PDF document. |
output |
'character' string.
File path for the JPEG image to write. If the path lacks a |
page |
'integer' number. Page number to render. Defaults to 1 (the cover page). |
width |
'integer' number. Output image width in pixels. Height is set automatically to preserve the page's aspect ratio. Defaults to 300. |
depth |
'integer' number. Image color depth, either 8 or 16. Defaults to 8. |
quality |
'integer' number between 0 and 100. JPEG compression quality. Defaults to 70. |
timeout |
'numeric' number. Maximum time, in seconds, to allow the PDF page to render before the operation is aborted. |
The selected page is rendered at a resolution computed from the requested output width (to avoid rasterizing a needlessly large image), resized with a high-quality Lanczos filter while preserving aspect ratio, flattened onto a white background, converted to an sRGB JPEG at the given color depth, and stripped of metadata before being written.
The Poppler-backed reads and the page rasterization are run in a child
process, so a native crash on a problematic PDF (which cannot be caught with
tryCatch) surfaces here as a normal R error instead of taking down the
session or aborting a batch run.
Returns the path to the image file, invisibly.
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
add_content to add cover images to the inlpubs package.
input <- system.file("extdata", "test.pdf", package = "inlpubs") path <- get_pdf_image(input) unlink(path)input <- system.file("extdata", "test.pdf", package = "inlpubs") path <- get_pdf_image(input) unlink(path)
Extract text from a PDF document and write it to a plain-text file, one page per line. Pages with an extractable text layer are read directly; pages without one (e.g. scanned images) fall back to optical character recognition (OCR). The text is normalized to ASCII before writing.
Requires the pdftools, tesseract, and callr packages; image preprocessing additionally requires magick.
get_pdf_text( input, output = tempfile(fileext = ".txt"), dpi = 300, psm = 1, force_ocr = FALSE, preprocess = FALSE, min_chars = 20, cores = NULL, timeout = 120 )get_pdf_text( input, output = tempfile(fileext = ".txt"), dpi = 300, psm = 1, force_ocr = FALSE, preprocess = FALSE, min_chars = 20, cores = NULL, timeout = 120 )
input |
'character' string. File path to the PDF document. |
output |
'character' string.
File path for the text file to write. If the path lacks a |
dpi |
'integer' number between 100 and 1200. Resolution, in dots per inch, at which pages are rendered before OCR. Higher values improve OCR accuracy at the cost of speed; 300 (the default) suits most documents, while 400 to 600 may help with small fonts or poor scans. Ignored for pages read directly from the text layer. |
psm |
'integer' number between 0 and 13. Tesseract Page Segmentation Mode, describing the expected page layout. The default of 1 segments the page automatically and detects orientation and script, which suits multi-column documents. |
force_ocr |
'logical' flag.
Whether to OCR every page regardless of its text layer. Use this when the
embedded text is known to be unreliable (e.g. fonts that extract as gibberish,
which |
preprocess |
'logical' flag.
Whether to grayscale, deskew, despeckle, and normalize each page image before
OCR, which improves accuracy on scanned documents at a modest per-page cost.
Requires the magick package. Applies only to pages that are OCR'd.
Defaults to |
min_chars |
'integer' number. Minimum number of non-whitespace characters a page's extracted text must have to be accepted without OCR. Pages below this threshold are sent to OCR. Defaults to 20. |
cores |
'integer' number.
Number of parallel workers to use for OCR. When |
timeout |
'numeric' number. Maximum time, in seconds, to allow each child-process call to run before it is aborted. Applied independently to the text-extraction call and the page-rendering call. Defaults to 120. |
Direct extraction is attempted first, as it is faster and more accurate than
OCR for born-digital PDFs; a page is OCR'd only when its text layer yields
fewer than min_chars non-whitespace characters, or when force_ocr is
TRUE. Poppler reads and page rendering run in isolated child processes, so
a renderer crash surfaces as a normal R error rather than aborting the
session.
Directly extracted text is reordered into human reading order from word
bounding boxes: full-width headers and captions are set aside, then the body
is split into columns only on strong evidence of a multi-column layout. OCR
uses Tesseract's LSTM engine, run in parallel across cores workers when
several pages need it. The result is normalized to strictly ASCII: selected
scientific symbols become ASCII tokens, accents are transliterated, line-break
hyphenation is rejoined, and quotes, control characters, and repeated
punctuation and whitespace are cleaned up.
Returns the path to the text file, invisibly. Each page of the PDF is written as a separate line.
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
add_content to add extracted text to the inlpubs-package corpus.
## Not run: input <- system.file("extdata", "test.pdf", package = "inlpubs") path <- get_pdf_text(input) unlink(path) ## End(Not run)## Not run: input <- system.file("extdata", "test.pdf", package = "inlpubs") path <- get_pdf_text(input) unlink(path) ## End(Not run)
Create a word cloud from a term-frequency table and save it as a PNG
file. The most frequent terms are rendered, laid out within the chosen shape.
Requires the htmltools, htmlwidgets, magick, webshot2,
and wordcloud2 packages. System dependencies are
ImageMagick (for displaying the PNG),
OptiPNG (for PNG compression), and a
Chrome or Chromium-based browser with
support for the Chrome DevTools protocol. Use
chromote::find_chrome() to locate the browser.
make_wordcloud( x, max_terms = 200, size = 1, shape = "circle", ellipticity = 0.65, ..., width = 910, output = NULL, display = FALSE )make_wordcloud( x, max_terms = 200, size = 1, shape = "circle", ellipticity = 0.65, ..., width = 910, output = NULL, display = FALSE )
x |
'data.frame'.
Term-frequency table containing at least the columns |
max_terms |
'integer' number. Maximum number of terms to include, taken in order of decreasing frequency. Defaults to 200. |
size |
'numeric' number. Font-size scaling factor. Defaults to 1. |
shape |
'character' string.
Shape of the cloud. One of |
ellipticity |
'numeric' number between 0 and 1. Degree of flattening applied to the shape. Defaults to 0.65. |
... |
Additional arguments passed to |
width |
'integer' number.
Image width in pixels. Defaults to 910. Image height is derived from |
output |
'character' string. Path to the output PNG file. Defaults to a temporary file. |
display |
'logical' flag.
Whether to display the saved PNG in a graphics window. Requires the magick
package. Defaults to |
Invisibly returns the file path to the word-cloud PNG.
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
mine_text to build a term-frequency table.
## Not run: d <- wordcloud2::demoFreq |> head(n = 10) colnames(d) <- c("term", "freq") file <- make_wordcloud(d, display = interactive()) unlink(file) ## End(Not run)## Not run: d <- wordcloud2::demoFreq |> head(n = 10) colnames(d) <- c("term", "freq") file <- make_wordcloud(d, display = interactive()) unlink(file) ## End(Not run)
Build a term-frequency table from document text. A term is a single word or, when n-gram tokenization is enabled, an ordered sequence of words.
mine_text(docs, ngmin = 1, ngmax = ngmin, sparse = NULL)mine_text(docs, ngmin = 1, ngmax = ngmin, sparse = NULL)
docs |
'list' or 'character' vector.
Document text to analyze. Each element holds the extracted text of a single
document and may itself be a character vector (its pieces are concatenated).
|
ngmin, ngmax
|
'integer' numbers.
Minimum and maximum number of words per term (n-gram). The default
( |
sparse |
'numeric' number greater than 0 and less than 1, or |
Documents are cleaned before counting: URLs, escaped unicode sequences, HTML tags, and selected punctuation are removed; text is lowercased; numbers, English and SMART stopwords, and remaining punctuation are stripped; and whitespace is collapsed. HTML entities are decoded when the textutils package is available. When n-grams are requested, terms containing a repeated word are discarded.
A 'data.frame' term-frequency table with columns term, pub_id, and
freq, giving the number of times each term occurs in each document. Rows with
a zero count are omitted, and the table is sorted by term (ascending) then
frequency (descending).
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
search_terms to search within the resulting table, and
make_wordcloud to create a word cloud from it.
d <- c( "The quick brown fox jumps over the lazy lazy dog.", "Pack my brown box.", "Jazz fly brown dog." ) |> mine_text() d <- list( "A" = "The quick brown fox jumps over the lazy lazy dog.", "B" = c("Pack my brown box.", NA, "Jazz fly brown dog."), "C" = NA_character_ ) |> mine_text()d <- c( "The quick brown fox jumps over the lazy lazy dog.", "Pack my brown box.", "Jazz fly brown dog." ) |> mine_text() d <- list( "A" = "The quick brown fox jumps over the lazy lazy dog.", "B" = c("Pack my brown box.", NA, "Jazz fly brown dog."), "C" = NA_character_ ) |> mine_text()
Draw a stacked bar chart of INLPO publication counts by year, with USGS and non-USGS publications distinguished by color.
plot_pubs( pubs = inlpubs::pubs, author_id = NULL, full_range = TRUE, legend_loc = "topleft", colors = c(USGS = "#4682B4", `Non-USGS` = "#B47846"), ... )plot_pubs( pubs = inlpubs::pubs, author_id = NULL, full_range = TRUE, legend_loc = "topleft", colors = c(USGS = "#4682B4", `Non-USGS` = "#B47846"), ... )
pubs |
'pub' data frame.
Publications of the INLPO; see the |
author_id |
'character' vector, or |
full_range |
'logical' flag.
Whether the x-axis spans the year range of all publications in |
legend_loc |
'character' string.
Position of the legend, passed as the keyword location to
|
colors |
'character' vector of length 2.
Fill colors for the two series, in the order |
... |
Additional arguments passed to |
Invisibly returns a numeric vector giving the x-axis coordinates of
the bar midpoints, as returned by graphics::barplot().
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
pubs for the publications dataset.
plot_pubs()plot_pubs()
Bibliographic information for reports, articles, maps, and theses related to scientific monitoring and research conducted by the U.S. Geological Survey (USGS), Idaho Water Science Center, Idaho National Laboratory Project Office (INLPO).
pubspubs
An object of class 'pub' that inherits from the 'data.frame' class and includes the following columns:
pub_idUnique identifier for the publication (the table's primary
key), in upper camel case (for example, "FisherOthers2012").
institutionName of the institution that published and/or sponsored the report.
typeType of publication, such as "Open-File Report",
"Data Series", or "Manual".
text_refText reference (the in-text citation) excluding the year of
publication, such as "Dietz" or "Treinen and others".
yearYear of publication.
author_idA named list of character vectors giving the identifier(s)
of the contributing author(s), in author order; each value is a foreign key
referencing the author_id primary key of the authors table. List names
match pub_id.
titleTitle of publication.
bibentryA named list of bibentry objects holding
the full bibliographic record, from which formatted citations and BibTeX
entries are derived. List names match pub_id.
abstractAbstract of publication, or NA when unavailable.
annotationAnnotation summarizing the publication, or NA when none
is provided.
annotation_srcIdentifier (pub_id) of the publication the annotation
was taken from, or NA when not applicable
(Knobel and others, 2005; Bartholomay, 2022).
filesA named list of character vectors naming the file(s) associated
with the publication, primary document first, or NULL when no files are
recorded. List names match pub_id.
Many of these publications are available through the USGS Publications Warehouse.
Bartholomay, R.C., 2022, Historical development of the U.S. Geological Survey hydrological monitoring and investigative programs at the Idaho National Laboratory, Idaho, 2002-2020: U.S. Geological Survey Open-File Report 2022-1027 (DOE/ID-22256), 54 p., doi:10.3133/ofr20221027.
Knobel, L.L., Bartholomay, R.C., and Rousseau, J.P., 2005, Historical development of the U.S. Geological Survey hydrologic monitoring and investigative programs at the Idaho National Engineering and Environmental Laboratory, Idaho, 1949 to 2001: U.S. Geological Survey Open-File Report 2005–1223 (DOE/ID–22195), 93 p., doi:10.3133/ofr20051223.
authors for the contributing authors referenced by author_id,
terms for term frequencies derived from publication text, and
search_terms to query publications by term.
# Subset Fisher and others (2012) and display its structure: id <- "FisherOthers2012" pub <- pubs[id, ] str(pub, max.level = 3, width = 75, strict.width = "cut") # Print the suggested citation: attr(unclass(pub$bibentry[[1]])[[1]], which = "textVersion") # Print the authors' full names: format(pub$bibentry[[1]]$author, include = c("given", "family")) # Print the abstract: pub$abstract# Subset Fisher and others (2012) and display its structure: id <- "FisherOthers2012" pub <- pubs[id, ] str(pub, max.level = 3, width = 75, strict.width = "cut") # Print the suggested citation: attr(unclass(pub$bibentry[[1]])[[1]], which = "textVersion") # Print the authors' full names: format(pub$bibentry[[1]]$author, include = c("given", "family")) # Print the abstract: pub$abstract
Search a term-frequency table by pattern or frequency.
search_terms( x, data = inlpubs::terms, ignore_case = TRUE, ..., low_freq = 1, high_freq = Inf, simplify = TRUE )search_terms( x, data = inlpubs::terms, ignore_case = TRUE, ..., low_freq = 1, high_freq = Inf, simplify = TRUE )
x |
'character' string. Regular-expression pattern to search for among the table's terms. |
data |
'term' and 'data.frame' class.
Term-frequency table to search, with columns |
ignore_case |
'logical' flag.
Whether to ignore character case when matching. Defaults to |
... |
Additional arguments passed to |
low_freq |
'numeric' number. Lower frequency bound; terms occurring fewer than this many times are excluded. Defaults to 1. |
high_freq |
'numeric' number.
Upper frequency bound; terms occurring more than this many times are excluded.
Defaults to |
simplify |
'logical' flag.
Whether to return only the unique publication identifiers ( |
If simplify = TRUE, a 'character' vector of unique publication
identifiers, ordered by the most frequent matching term first. If
simplify = FALSE, a 'data.frame' of matching rows sorted by decreasing
frequency.
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
mine_text to build a term-frequency table.
search_terms("mlms") out <- search_terms("mlms", simplify = FALSE) head(out)search_terms("mlms") out <- search_terms("mlms", simplify = FALSE) head(out)
A term-frequency table giving the number of times each term appears in each publication, for publications by the U.S. Geological Survey (USGS), Idaho Water Science Center, Idaho National Laboratory Project Office (INLPO). The table has one row per term-publication pairing.
termsterms
An object of class 'term' that inherits from the 'data.frame' class and includes the following columns:
termTerm (a single word, or a multi-word n-gram), stored as a factor. Terms are lowercase ASCII.
pub_idIdentifier of the publication in which the term appears, stored
as a factor; a foreign key referencing the pub_id primary key of the
pubs table.
freqNumber of times the term occurs in that publication.
The publication text was sourced from the original PDF documents using the
get_pdf_text function, and term frequencies were extracted from the text
using the mine_text function.
mine_text to build a term-frequency table, search_terms to search
within it, and make_wordcloud to visualize it.
str(terms, max.level = 3, width = 75, strict.width = "cut") # Most frequent terms across all publications: freq_by_term <- tapply(terms$freq, terms$term, FUN = sum) sort(freq_by_term, decreasing = TRUE) |> head(n = 10)str(terms, max.level = 3, width = 75, strict.width = "cut") # Most frequent terms across all publications: freq_by_term <- tapply(terms$freq, terms$term, FUN = sum) sort(freq_by_term, decreasing = TRUE) |> head(n = 10)