| Title: | R Interface to Copernicus Marine Service |
|---|---|
| Description: | Provides an R interface to the Copernicus Marine Service for downloading and accessing marine data. Integrates with the official 'copernicusmarine' Python library through 'reticulate'. Requires Python 3.7+ and a free Copernicus Marine account. See <https://marine.copernicus.eu/> and <https://pypi.org/project/copernicusmarine/> for more information. |
| Authors: | Hans Ttito [aut, cre] (ORCID: <https://orcid.org/0000-0003-3732-9419>) |
| Maintainer: | Hans Ttito <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-06-04 09:18:29 UTC |
| Source: | https://github.com/hansttito/copernicusr |
Removes stored Copernicus Marine credentials from session options and environment variables.
copernicus_clear_credentials()copernicus_clear_credentials()
Invisible TRUE.
copernicus_clear_credentials()copernicus_clear_credentials()
Downloads .nc files from the Copernicus Marine catalog. Allows specifying all options of the Python function. Uses stored credentials from options/environment variables if available.
copernicus_download( dataset_id, variables, start_date, end_date, bbox = c(-180, 179.92, -80, 90), depth = c(0.494, 0.494), dataset_version = "202406", output_file = NULL, username = NULL, password = NULL, verbose_download = TRUE, ... )copernicus_download( dataset_id, variables, start_date, end_date, bbox = c(-180, 179.92, -80, 90), depth = c(0.494, 0.494), dataset_version = "202406", output_file = NULL, username = NULL, password = NULL, verbose_download = TRUE, ... )
dataset_id |
ID of the dataset (exact). |
variables |
Vector or list of variables to download. |
start_date |
Download start date (YYYY-MM-DD). |
end_date |
Download end date (YYYY-MM-DD). |
bbox |
Vector of 4 values (xmin, xmax, ymin, ymax) for the region. |
depth |
Vector of 2 values: minimum and maximum depth. |
dataset_version |
Dataset version. |
output_file |
Output file path. By default, generates one in tempdir(). |
username |
Copernicus Marine username (optional, will try to get from stored credentials). |
password |
Copernicus Marine password (optional, will try to get from stored credentials). |
verbose_download |
Show detailed messages. |
... |
Other extra arguments passed to the Python function. |
Absolute path to the downloaded file, or NULL if it fails.
Retrieves stored Copernicus Marine credentials from session options or environment variables.
copernicus_get_credentials(mask_password = TRUE)copernicus_get_credentials(mask_password = TRUE)
mask_password |
Logical. Should password be masked in output? Default: TRUE. |
List with username and password (optionally masked).
# Get credentials (password masked) copernicus_get_credentials() # Get credentials (password visible - use with caution) copernicus_get_credentials(mask_password = FALSE)# Get credentials (password masked) copernicus_get_credentials() # Get credentials (password visible - use with caution) copernicus_get_credentials(mask_password = FALSE)
Checks if the Python module is properly loaded and credentials are configured to use Copernicus Marine. Returns TRUE if everything is ready.
copernicus_is_ready(verbose = TRUE)copernicus_is_ready(verbose = TRUE)
verbose |
Show detailed status information. |
TRUE if the Python module is loaded and credentials are available.
Opens a dataset directly from Copernicus Marine using open_dataset. Returns a Python xarray.Dataset object that can be processed in R. Useful for exploring data without downloading full files. Uses stored credentials from options/environment variables if available.
copernicus_open_dataset( dataset_id, variables = NULL, start_date = NULL, end_date = NULL, bbox = NULL, depth = NULL, dataset_version = NULL, username = NULL, password = NULL, verbose_open = TRUE, ... )copernicus_open_dataset( dataset_id, variables = NULL, start_date = NULL, end_date = NULL, bbox = NULL, depth = NULL, dataset_version = NULL, username = NULL, password = NULL, verbose_open = TRUE, ... )
dataset_id |
ID of the dataset (exact). |
variables |
Vector or list of variables to open. If NULL, opens all. |
start_date |
Start date (YYYY-MM-DD). Optional. |
end_date |
End date (YYYY-MM-DD). Optional. |
bbox |
Vector of 4 values (xmin, xmax, ymin, ymax) for the region. Optional. |
depth |
Vector of 2 values: minimum and maximum depth. Optional. |
dataset_version |
Dataset version. Optional. |
username |
Copernicus Marine username (optional, will try to get from stored credentials). |
password |
Copernicus Marine password (optional, will try to get from stored credentials). |
verbose_open |
Show detailed messages. |
... |
Other extra arguments passed to the Python function. |
Python xarray.Dataset object, or NULL if it fails.
Helper function to set credentials in .Renviron file for persistent storage. This is more secure than storing in scripts.
copernicus_set_env_credentials(username, password, overwrite = FALSE)copernicus_set_env_credentials(username, password, overwrite = FALSE)
username |
Character. Copernicus Marine username. |
password |
Character. Copernicus Marine password. |
overwrite |
Logical. Overwrite existing credentials in .Renviron? Default: FALSE. |
Invisible TRUE if successful.
## Not run: # Set credentials in .Renviron (will persist across R sessions) copernicus_set_env_credentials("your_username", "your_password") ## End(Not run)## Not run: # Set credentials in .Renviron (will persist across R sessions) copernicus_set_env_credentials("your_username", "your_password") ## End(Not run)
Sets up Copernicus Marine Service credentials using various methods:
Function parameters
R session options
Environment variables
Interactive prompt (only in interactive sessions)
copernicus_setup_credentials( username = NULL, password = NULL, store_credentials = TRUE, prompt_if_missing = interactive() )copernicus_setup_credentials( username = NULL, password = NULL, store_credentials = TRUE, prompt_if_missing = interactive() )
username |
Character. Copernicus Marine username. If NULL, tries other methods. |
password |
Character. Copernicus Marine password. If NULL, tries other methods. |
store_credentials |
Logical. Store credentials in session options? Default: TRUE. |
prompt_if_missing |
Logical. Prompt user for credentials if not found? Default: TRUE only in interactive sessions. |
Invisible list with username and password (password is masked).
## Not run: # Set credentials directly copernicus_setup_credentials("username", "password") # Set credentials and store in options copernicus_setup_credentials("username", "password", store_credentials = TRUE) # Try to get from environment/options copernicus_setup_credentials() ## End(Not run)## Not run: # Set credentials directly copernicus_setup_credentials("username", "password") # Set credentials and store in options copernicus_setup_credentials("username", "password", store_credentials = TRUE) # Try to get from environment/options copernicus_setup_credentials() ## End(Not run)
Performs a small test download to validate that the whole system works. Uses stored credentials if available. Downloads to tempdir().
copernicus_test(username = NULL, password = NULL)copernicus_test(username = NULL, password = NULL)
username |
Copernicus Marine username (optional). Will try to get from stored credentials first. |
password |
Copernicus Marine password (optional). Will try to get from stored credentials first. |
TRUE if the test was successful.
Performs a test dataset opening to validate that the open_dataset function works. Uses stored credentials if available.
copernicus_test_open(username = NULL, password = NULL)copernicus_test_open(username = NULL, password = NULL)
username |
Copernicus Marine username (optional, will try to get from stored credentials first). |
password |
Copernicus Marine password (optional, will try to get from stored credentials first). |
TRUE if the test was successful.
Tests if the stored credentials work by attempting a simple API call.
copernicus_validate_credentials()copernicus_validate_credentials()
Logical. TRUE if credentials are valid, FALSE otherwise.
## Not run: copernicus_validate_credentials() ## End(Not run)## Not run: copernicus_validate_credentials() ## End(Not run)
Sets up the Python environment and loads the copernicusmarine module for use in R. Optionally configures Copernicus Marine credentials for the session. It is recommended to run this once per session before calling other functions in the package. Note: This function does not install Python packages by default for CRAN compliance.
setup_copernicus( install_copernicus = FALSE, username = NULL, password = NULL, store_credentials = TRUE )setup_copernicus( install_copernicus = FALSE, username = NULL, password = NULL, store_credentials = TRUE )
install_copernicus |
Logical. Should the copernicusmarine package be installed in Python if not available? Default: FALSE (changed for CRAN compliance). |
username |
Character. Copernicus Marine username. If NULL, will try to get from options or environment variables. |
password |
Character. Copernicus Marine password. If NULL, will try to get from options or environment variables. |
store_credentials |
Logical. Should credentials be stored in session options? Default: TRUE. |
Invisible TRUE if the configuration was successful.
## Not run: # Basic setup without credentials (manual Python package installation required) setup_copernicus() # Setup with credentials setup_copernicus(username = "your_username", password = "your_password") # Setup reading from environment variables setup_copernicus() # Will look for COPERNICUS_USERNAME and COPERNICUS_PASSWORD # Setup and store credentials for session setup_copernicus(username = "user", password = "pass", store_credentials = TRUE) ## End(Not run)## Not run: # Basic setup without credentials (manual Python package installation required) setup_copernicus() # Setup with credentials setup_copernicus(username = "your_username", password = "your_password") # Setup reading from environment variables setup_copernicus() # Will look for COPERNICUS_USERNAME and COPERNICUS_PASSWORD # Setup and store credentials for session setup_copernicus(username = "user", password = "pass", store_credentials = TRUE) ## End(Not run)