The credentials of the user are stored using the keyring
package. With the following command a user can be added to the keyring.
Run this line once, it will store your credentials in keyring. After
that every time you load move2
and execute a download
function from movebank, these functions will retrieve your credentials
from keyring.
The keyring
package can use several mechanisms to store
credentials, these are called backends. Some of these backends are
operating system dependent, others are more general. Some of the
operating systems dependent backends have the advantage that they do not
require providing credentials when opening a new R session.
The move2
package uses the default backend as is
returned by keyring::default_backend()
, this function thus
shows the backend move2
is using. If you want to change the
default you can use the keyring_backend
option, for more
details see the documentation in the keyring package.
macOS and Windows generally do not
require entering an extra password for keyring. The default in
Linux is often the file
backend which can
be confusing as it creates an encrypted file with credentials that need
a password to unlock. In this case a separate password for the keyring
file has to be entered for each new R session before the movebank
password can be accessed. To avoid having to enter each time a keyring
password the Secret Service API can be used by installing the
libsecret
library. (Debian/Ubuntu:
libsecret-1-dev
; Recent RedHat, Fedora and CentOS systems:
libsecret-devel
)
key_name
If you have multiple user accounts on movebank, the easiest way is to
give each of them a key name with the argument key_name
.
For the most used account also the default option can be used. The
movebank_store_credentials()
only has to be executed once
for each account. After that the credentials will be retrieved from
keyring.
## store credentials for the most used account.
movebank_store_credentials("myUserName", "myPassword")
## store credentials for another movebank account
movebank_store_credentials("myUserName_2", "myPassword_2", key_name = "myOtherAccount")
When you want to download from Movebank using your default movebank account, nothing has to be specified before the download functions. If you want to download from Movebank with another account, than you should execute the line below, specifying the key name of the account to use, before the download functions are executed.
If in one script/Rsession you are using several accounts, to use the credentials of the default account execute the line below:
To check which accounts are stored in keyring:
The service
column corresponds to the names provided in
key_name
. The account entered without a key name (the
default) will be called movebank
. Note that the key names
have to be unique, if there are several usernames with the same key name
(service), it will cause an error.
To deleted credentials from keyring:
## for the default account
movebank_remove_credentials()
#> There is 1 key removed from the keyring.
## for an account with a key name
movebank_remove_credentials(key_name = "myOtherAccount")
#> There is 1 key removed from the keyring.
Next we can check if the keys are successfully removed:
Here you can check if the movebank
service is
successfully removed.
Using the function movebank_download_study_info
it is
possible to download information for all studies, for all studies that
have certain property or for a single study. Any column of the table can
be used to download only the information of the studies that comply with
the selected property. This table contains all the information that can
be seen on the “Study page” on the Movebank webpage, plus additional
information about download rights and ownership.
NOTE: due to incorrect timestamps in some Movebank studies, the
function movebank_download_study_info()
sometimes returns a
Warning message as the one in the example below. You can ignore
this (see issue #17).
The function movebank_download_deployment
downloads a
table with the associated information to individuals, tags and
deployments. This table reassembles the “Reference Data” table that can
be downloaded from the Movebank webpage.
With the function movebank_download_study
the complete
study from Movebank can be downloaded. There are many options to
download a subset of the complete study. The study_id
can
either be specified either as an integer
or
character
with respectively the id or name of the
study.
To get the study ID of a Movebank study use
movebank_get_study_id
movebank_download_study_info(study_id = 2911040)$sensor_type_ids
movebank_download_study(
study_id = 2911040,
sensor_type_id = c("gps", "acceleration")
)
movebank_download_study(
study_id = "Galapagos Albatrosses",
sensor_type_id = "gps",
individual_local_identifier = "unbanded-160"
)
movebank_download_study(
study_id = 2911040,
sensor_type_id = "gps",
individual_local_identifier = c("1094-1094", "1103-1103")
)
## it is also possible to use the numerical identifiers
movebank_download_study(
study_id = 2911040,
sensor_type_id = "gps",
individual_id = c(2911086, 2911065)
)
movebank_download_study(2911040,
sensor_type_id = "acceleration",
individual_local_identifier = "1094-1094"
)
Note that the sensor_type_id
can either be specified
either as an integer
or character
with
respectively the ‘id’ or ‘external_id’ of the sensor. Here is how you
get the correspondence table of sensor name and id:
timestamp_*
arguments can either be formatted as a
POSIXct
timestamp, Date
or a character string
(e.g. "20080604133046000"
(yyyyMMddHHmmssSSS)). The
timestamp_*
arguments can also be used separately.movebank_download_study(2911040,
sensor_type_id = "gps",
timestamp_start = as.POSIXct("2008-08-01 00:00:00"),
timestamp_end = as.POSIXct("2008-08-02 00:00:00")
)
attributes = NULL
can be used as it reduces the
columns to download to the bare minimum. All individual attributes are
downloaded as this does not take much time. Note that this option should
only be used when downloading location data (by specifying the sensor),
as only timestamps, location and track id is downloaded.## get all attributes available for a specific study and sensor
movebank_retrieve(
entity_type = "study_attribute",
study_id = 2911040,
sensor_type_id = "gps"
)$short_name
movebank_download_study(
study_id = 2911040,
sensor_type_id = "gps",
attributes = c("height_above_ellipsoid", "eobs_temperature")
)
For specific request it might be useful to directly retrieve
information from the Movebank API. The movebank_retrieve
function provides this functionality. The first argument is the entity
type you would like to retrieve information for (e.g. tag
or event
). A study id is always required and other
arguments make it possible to select. For more details how to use the
api see the documentation.
One common reason to use this options is to retrieve undeployed
locations. In some cases a set of locations is collected before the tag
attached to the animal for quality control or error measurements. The
example below shows how all records for a specific tag can be retrieved.
Filtering for locations where the deployment_id
is
NA
, returns those locations that were collected while the
tag was not deployed. The timestamp_start
and
timestamp_end
might be good argument to filter down the
data even more in the call to movebank_retrieve
. By
omitting the argument tag_local_identifier
the entire study
can downloaded. With the argument sensor_type_id
the
sensors can be specified.
movebank_retrieve("event",
study_id = 1259686571,
tag_local_identifier = "193967",
attributes = "all"
) %>%
filter(is.na(deployment_id))