Skip to content

Commit

Permalink
Document behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Mar 24, 2024
1 parent 004f91d commit dc9b006
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
20 changes: 11 additions & 9 deletions R/Driver.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,27 @@ duckdb <- function(dbdir = DBDIR_MEMORY, read_only = FALSE, bigint = "numeric",
check_flag(read_only)
check_bigint(bigint)

# R packages are not allowed to write extensions into home directory, so use R_user_dir instead
if (!("extension_directory" %in% names(config))) {
config["extension_directory"] <- file.path(tools::R_user_dir("duckdb", "data"), "extensions")
}
if (!("secret_directory" %in% names(config))) {
config["secret_directory"] <- file.path(tools::R_user_dir("duckdb", "data"), "stored_secrets")
}

dbdir <- path_normalize(dbdir)
if (dbdir != DBDIR_MEMORY) {
drv <- driver_registry[[dbdir]]
# We reuse an existing driver object if the database is still alive.
# If not, we fall back to creating a new driver object with a new database.
if (!is.null(drv) && rapi_lock(drv@database_ref)) {
# FIXME: Check that readonly and config are identical
# We don't care about different read_only or config settings here.
# The bigint setting can be actually picked up by dbConnect(), we update it here.
drv@bigint <- bigint
return(drv)
}
}

# R packages are not allowed to write extensions into home directory, so use R_user_dir instead
if (!("extension_directory" %in% names(config))) {
config["extension_directory"] <- file.path(tools::R_user_dir("duckdb", "data"), "extensions")
}
if (!("secret_directory" %in% names(config))) {
config["secret_directory"] <- file.path(tools::R_user_dir("duckdb", "data"), "stored_secrets")
}

# Always create new database for in-memory,
# allows isolation and mixing different configs
drv <- new(
Expand Down
10 changes: 8 additions & 2 deletions R/dbConnect__duckdb_driver.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#' data is kept in RAM.
#' @param ... Ignored
#' @param debug Print additional debug information such as queries
#' @param read_only Set to `TRUE` for read-only operation
#' @param read_only Set to `TRUE` for read-only operation.
#' For file-based databases, this is only applied when the database file is opened for the first time.
#' Subsequent connections (via the same `drv` object or a `drv` object pointing to the same path)
#' will silently ignore this flag.
#' @param timezone_out The time zone returned to R, defaults to `"UTC"`, which
#' is currently the only timezone supported by duckdb.
#' If you want to display datetime values in the local timezone,
Expand All @@ -18,7 +21,10 @@
#' is chosen, the timestamp will be returned as it would appear in the specified time zone.
#' If `"force"` is chosen, the timestamp will have the same clock
#' time as the timestamp in the database, but with the new time zone.
#' @param config Named list with DuckDB configuration flags
#' @param config Named list with DuckDB configuration flags, see
#' <https://duckdb.org/docs/configuration/overview#configuration-reference> for the possible options.
#' These flags are only applied when the database object is instantiated.
#' Subsequent connections will silently ignore these flags.
#' @param bigint How 64-bit integers should be returned. There are two options: `"numeric"` and `"integer64"`.
#' If `"numeric"` is selected, bigint integers will be treated as double/numeric.
#' If `"integer64"` is selected, bigint integers will be set to bit64 encoding.
Expand Down
10 changes: 8 additions & 2 deletions man/duckdb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc9b006

Please sign in to comment.