Skip to contents

ScienceBase item class

Usage

as.sbitem(x, ...)

# S3 method for default
as.sbitem(x, ...)

is.sbitem(x)

Arguments

x

Input, variety of things, character, list, or sbitem class object

...

Further args passed on to item_get, only in the method for character class inputs

Examples

# \donttest{
# Single item from item_get()
item_get("4f4e4b24e4b07f02db6aea14")
#> Request failed [404]. Retrying in 1.7 seconds...
#> Request failed [404]. Retrying in 1.6 seconds...
#> Warning: Sciencebase returned '404' -- item doesn't exist or is secured
#> Request failed [404]. Retrying in 1 seconds...
#> Request failed [404]. Retrying in 1 seconds...
#> Warning: Sciencebase returned '404' -- item doesn't exist or is secured
#> NULL

# Get many w/ e.g., an lapply() call
library("httr")
res <- query_items(list(s = "Search", q = "water", format = "json"))
if(res$status != 404) {
  ids <- vapply(httr::content(res)$items, "[[", "", "id")
  (out <- lapply(ids[1:3], item_get))
}
#> [[1]]
#> <ScienceBase Item> 
#>   Title: H.S.P. #Water Well Water Well
#>   Creator/LastUpdatedBy:      / 
#>   Provenance (Created / Updated):  2020-03-18T17:05:02Z / 2020-03-18T17:05:02Z
#>   Children: FALSE
#>   Item ID: 5e7254bee4b01d50926a6c66
#>   Parent ID: 4f4e49cbe4b07f02db5d8760
#> 
#> [[2]]
#> <ScienceBase Item> 
#>   Title: Water
#>   Creator/LastUpdatedBy:      / 
#>   Provenance (Created / Updated):  2016-09-29T15:16:41Z / 2018-06-18T11:56:09Z
#>   Children: FALSE
#>   Item ID: 57ed3059e4b090825011d461
#>   Parent ID: 57ed2fa1e4b090825011d45b
#> 
#> [[3]]
#> <ScienceBase Item> 
#>   Title: H.S.P. #Water well Water well
#>   Creator/LastUpdatedBy:      / 
#>   Provenance (Created / Updated):  2020-03-18T17:21:46Z / 2020-03-18T17:21:46Z
#>   Children: FALSE
#>   Item ID: 5e7258aae4b01d50926aaf76
#>   Parent ID: 4f4e49cbe4b07f02db5d8760
#> 
# create item class from only an item ID
as.sbitem("4f4e4b24e4b07f02db6aea14")
#> Request failed [404]. Retrying in 1.8 seconds...
#> Request failed [404]. Retrying in 1.9 seconds...
#> Warning: Sciencebase returned '404' -- item doesn't exist or is secured
#> NULL

# sbitem gives back itself
(x <- as.sbitem("4f4e4b24e4b07f02db6aea14"))
#> Request failed [404]. Retrying in 1 seconds...
#> Request failed [404]. Retrying in 1.5 seconds...
#> Warning: Sciencebase returned '404' -- item doesn't exist or is secured
#> NULL
as.sbitem(x)
#> NULL
# }