Learn R Programming

⚠️There's a newer version (1.4.1) of this package.Take me there.

ScienceBase R Tools

Tools for interfacing R with ScienceBase data services.

Package Description

This package provides a rich interface to USGS’s ScienceBase, a data cataloging and collaborative data management platform. For further information, see the sbtools manuscript in The R Journal (USGS IP-075498). See citation('sbtools') for how to cite the package.

Recommended Citation:

  Winslow, LA, S Chamberlain, AP Appling, and JS Read. 2016. sbtools: 
  A package connecting R to cloud-based data for collaborative online 
  research. The R Journal 8:387-398.

Package source code DOI: https://doi.org/10.5066/P912NGFV

LinuxTest Coverage

Current CRAN information

VersionMonthly DownloadsTotal Downloads

Package Installation

To install the sbtools package, you must be using R 3.0 or greater and run the following command:

install.packages("sbtools")

To get cutting-edge changes, install from GitHub using the devtools packages:

remotes::install_github("DOI-USGS/sbtools")

Reporting bugs

Please consider reporting bugs and asking questions on the Issues page:

https://github.com/DOI-USGS/sbtools/issues

Examples

library(sbtools)

# Query ScienceBase for data about Antarctica
query_sb_text('Antarctica', limit=1)
#> [[1]]
#> <ScienceBase Item> 
#>   Title: Tectonics of Antarctica
#>   Creator/LastUpdatedBy:      / 
#>   Provenance (Created / Updated):   / 
#>   Children: 
#>   Item ID: 505ba488e4b08c986b3203fa
#>   Parent ID: 4f4e4771e4b07f02db47e1e4

# Query for a specific DOI
query_sb_doi('10.5066/F7M043G7')
#> list()

# Inspect the contents of the above item
children <- item_list_children('557f0367e4b023124e8ef621')
#> Request failed [404]. Retrying in 1 seconds...
#> Request failed [404]. Retrying in 2.2 seconds...
#> Item not found for ID=557f0367e4b023124e8ef621. Either the item does not exist or the item is secured and requires authentication to access.FALSE
#> Request failed [404]. Retrying in 1.7 seconds...
#> Request failed [404]. Retrying in 1 seconds...
sapply(children, function(child) child$title)
#> list()

# Log in (requires a ScienceBase account) and create an item
authenticate_sb(Sys.getenv("sb_user")) # type in password
my_home_item <- user_id()
new_item <- item_create(title = 'new test item', parent_id = my_home_item)
test.txt <- file.path(tempdir(), 'test.txt')
writeLines(c('this is','my data file'), "test.txt")
item_append_files(new_item, "test.txt")
#> <ScienceBase Item> 
#>   Title: new test item
#>   Creator/LastUpdatedBy:     dblodgett@usgs.gov / dblodgett@usgs.gov
#>   Provenance (Created / Updated):  2022-11-03T19:47:46Z / 2022-11-03T19:47:48Z
#>   Children: FALSE
#>   Item ID: 63641ae2d34ebe4425074d93
#>   Parent ID: 4f7afec1e4b0b2f259355f30
item_list_files(new_item)$fname
#> [1] "test.txt"

item_rm(new_item)
#> Response [https://www.sciencebase.gov/catalog/item/63641ae2d34ebe4425074d93?format=json]
#>   Date: 2022-11-03 19:47
#>   Status: 200
#>   Content-Type: <unknown>
#> <EMPTY BODY>
unlink("test.txt")

Release Procedure

For release of the sbtools package, a number of steps are required.

  1. Ensure all checks pass and code coverage is adequate.
  2. Ensure NEWS.md reflects updates in version.
  3. Update DESCRIPTION to reflect release version.
  4. Build source package and upload to CRAN.
  5. Once accepted to CRAN, convert DISCLAIMER.md to approved language.
  6. Change references to main branch in code.json to release version.
  7. Commit changes and tag repository at release version. Push tag.
  8. Change code.json and DISCLAIMER.md back to development mode.

Disclaimer

This software has been approved for release by the U.S. Geological Survey (USGS). Although the software has been subjected to rigorous review, the USGS reserves the right to update the software as needed pursuant to further analysis and review. No warranty, expressed or implied, is made by the USGS or the U.S. Government as to the functionality of the software and related material nor shall the fact of release constitute any such warranty. Furthermore, the software is released on condition that neither the USGS nor the U.S. Government shall be held liable for any damages resulting from its authorized or unauthorized use.

This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey, an agency of the United States Department of Interior. For more information, see the official USGS copyright policy

Copy Link

Version

Install

install.packages('sbtools')

Monthly Downloads

549

Version

1.2.0

License

CC0

Issues

Pull Requests

Stars

Forks

Maintainer

David Blodgett

Last Published

April 30th, 2023

Functions in sbtools (1.2.0)

item_append_files

Upload File to Item
item_create

Create a new SB item
identifier_exists

Check if identifier exists
authenticate_sb

Authenticate to SB for subsequent calls
item_file_download

Download files attached to item
folder_create

Create a folder
item_exists

check if identifier touple already exists on SB
is_logged_in

Check whether you're logged into a ScienceBase session
item_get

Retrieve SB item
current_session

Return current cached session
item_replace_files

Replace files associated with an item
item_list_children

Return IDs for all child items
item_move

Move item from one folder to another
item_get_parent

Get an item's parent ID
item_get_fields

Retrieve specific fields from an SB item
item_publish_cloud

Publish file to public cloud S3 bucket
item_rename_files

Rename item attached files
item_rm

Remove item from SB
item_rm_files

Remove files associated with an item
item_list_files

Get list of files attached to SB item
items_create

Create many new SB items
item_upload_create

#' Upload file(s) and create a new item
items_rm

Remove items from SB
item_upsert

Upsert an SB item
query_items

Query SB for items using generic query parameters
item_update_identifier

Add custom identifier to an existing item
item_upload_cloud

Upload File to Item Cloud Storage
query_sb

Query SB for items using generic query parameters
item_update

Update a SB item with new metadata
item_rm_recursive

Remove an item completely by recursively removing its child items
query_sb_doi

Query SB for specific DOI (Digital Object Identifier)
query_sb_text

Query SB for items containing specific text
query_sb_spatial

Query SB based on spatial extent
readPassword

Read in a password from the user
session_age

a convienence function for getting the age of a session.
sb_ping

Ping ScienceBase to see if it's available
sb_datatypes

Query SB for all available datatypes
session_details

Get session info
session_logout

Logout of a ScienceBase session
session_expired

Check whether an SB session is expired
session_age_reset

session reset age
query_item_in_folder

Search within an SB folder
items_update

Update many SB items with new metadata
query_item_identifier

Query SB for items based on custom identifier
session_renew

Checks current session and re-authenticates if necessary
sbtools_POST

generic POSTs for sbtools package package wrapped for generic POSTs that test sessions internally and wrap some errors
sbitem

ScienceBase item class
sbtools_PUT

generic PUTs for sbtools package
session_validate

Validate sbtools session state
query_sb_datatype

Query SB for specific data type
session_set

Set the session to a user-specified value
sbtools-package

R interface to ScienceBase
items_upsert

Upsert many SB items
sbtools_DELETE

generic DELETEs for sbtools package
set_expiration

Set the expiration
sbtools_GET

generic GETs for sbtools package
set_endpoint

Set SB endpoint
query_sb_date

Query SB for items within a date range
user_id

Get your parent ID