con <- DBI::dbConnect(duckdb::duckdb(dbdir = tempfile()))
# Install and load the 'motherduck' extension
load_extensions(con, "motherduck")
# Load multiple extensions
load_extensions(con, c("motherduck", "httpfs"))
DBI::dbDisconnect(con)Load and Install DuckDB/MotherDuck Extensions
Source: R/utils-md.R
Installs (if necessary) and loads valid DuckDB or MotherDuck extensions for the active connection.
Usage
load_extensions(.con, extension_names)Arguments
Value
Invisibly returns NULL. The function prints a CLI report of the extension status.
Details
The load_extensions() function first validates the provided DuckDB/MotherDuck connection, then checks which of the requested extensions are valid and not already installed. Valid extensions are installed and loaded into the current session. Invalid extensions are reported to the user. The function provides a detailed CLI report summarizing which extensions were successfully installed and loaded, and which were invalid.
It is especially useful for ensuring that required extensions, such as motherduck, are available in your database session. The CLI messages also provide guidance on listing all available extensions and installing additional DuckDB extensions.
See Also
Other db-con: install_extensions(), show_motherduck_token(), validate_extension_install_status(), validate_extension_load_status()