occ_download: Spin up a download request for GBIF occurrence data.

Description

Spin up a download request for GBIF occurrence data.

Usage

1
2
3
occ_download(..., body = NULL, type = "and",
  user = getOption("gbif_user"), pwd = getOption("gbif_pwd"),
  email = getOption("gbif_email"), callopts = list())

Arguments

...

One or more of query arguments to kick of a download job. If you use this, don't use body parameter. See Details.

body

if you prefer to pass in the payload yourself, use this parameter. if use this, don't ass anythig to the dots. accepts either an R list, or JSON. JSON is likely easier, since the JSON library jsonlite requires that you unbox strings that shouldn't be auto-converted to arrays, which is a bit tedious for large queries. optional

type

(charcter) One of equals (=), and (&), or (|), lessThan (<), lessThanOrEquals (<=), greaterThan (>), greaterThanOrEquals (>=), in, within, not (!), like

user

(character) User name within GBIF's website. Required. Set in your .Rprofile file with the option gbif_user

pwd

(character) User password within GBIF's website. Required. Set in your .Rprofile file with the option gbif_pwd

email

(character) Email address to recieve download notice done email. Required. Set in your .Rprofile file with the option gbif_email

callopts

Further named arguments passed on to POST

Details

Argument passed have to be passed as character (e.g., 'country = US'), with a space between key ('country'), operator ('='), and value ('US'). See the type parameter for possible options for the operator. This character string is parsed internally.

The value can be comma separated, in which case we'll turn that into a predicate combined with the OR operator, for example, "taxonKey = 2480946,5229208" will turn into '{ "type": "or", "predicates": [ { "type": "equals", "key": "TAXON_KEY", "value": "2480946" }, { "type": "equals", "key": "TAXON_KEY", "value": "5229208" } ] }'

Acceptable arguments to ... are:

References

See the API docs http://www.gbif.org/developer/occurrence#download for more info, and the predicates docs http://www.gbif.org/developer/occurrence#predicates

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
## Not run: 
# occ_download("basisOfRecord = LITERATURE")
# occ_download('taxonKey = 3119195')
# occ_download('decimalLatitude > 50')
# occ_download('elevation >= 9000')
# occ_download('decimalLatitude >= 65')
# occ_download("country = US")
# occ_download("institutionCode = TLMF")
# occ_download("catalogNumber = Bird.27847588")

# res <- occ_download('taxonKey = 7264332', 'hasCoordinate = TRUE')

# pass output directly, or later, to occ_download_meta for more information
# occ_download('decimalLatitude > 75') %>% occ_download_meta

# Multiple queries
# occ_download('decimalLatitude >= 65', 'decimalLatitude <= -65', type="or")
# gg <- occ_download('depth = 80', 'taxonKey = 2343454', type="or")

# complex example with many predicates
# shows example of how to do date ranges for both year and month
# res <- occ_download(
#  "taxonKey = 2480946,5229208",
#  "basisOfRecord = HUMAN_OBSERVATION,OBSERVATION,MACHINE_OBSERVATION",
#  "country = US",
#  "hasCoordinate = true",
#  "hasGeospatialIssue = false",
#  "year >= 1999",
#  "year <= 2011",
#  "month >= 3",
#  "month <= 8"
# )

# Using body parameter - pass in your own complete query
## as JSON
query1 <- '{"creator":"sckott",
  "notification_address":["myrmecocystus@gmail.com"],
  "predicate":{"type":"and","predicates":[
    {"type":"equals","key":"TAXON_KEY","value":"7264332"},
    {"type":"equals","key":"HAS_COORDINATE","value":"TRUE"}]}
 }'
# res <- occ_download(body = query, callopts=verbose())

## as a list
library(jsonlite)
query <- list(
  creator = unbox("sckott"),
  notification_address = "myrmecocystus@gmail.com",
  predicate = list(
    type = unbox("and"),
    predicates = list(
      list(type = unbox("equals"), key = unbox("TAXON_KEY"), value = unbox("7264332")),
      list(type = unbox("equals"), key = unbox("HAS_COORDINATE"), value = unbox("TRUE"))
    )
  )
)
# res <- occ_download(body = query, callopts=verbose())

## End(Not run)

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

All documentation is copyright its authors; we didn't write any of that.