diff --git a/DESCRIPTION b/DESCRIPTION index 62d3b0d..b3ff854 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,5 +19,6 @@ Imports: openssl, shiny, shinycssloaders, - DBI, + DBI +Suggests: duckdb diff --git a/NAMESPACE b/NAMESPACE index 6553203..676bd13 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,7 +4,6 @@ export(gwalkr) export(gwalkrOutput) export(renderGwalkr) import(DBI) -import(duckdb) import(htmlwidgets) import(openssl) import(shiny) diff --git a/R/duckdb_utils.R b/R/duckdb_utils.R index 6ba8ffd..7d91b6d 100644 --- a/R/duckdb_utils.R +++ b/R/duckdb_utils.R @@ -1,5 +1,4 @@ library(DBI) -library(duckdb) my_env <- new.env() diff --git a/R/gwalkr.R b/R/gwalkr.R index db7d790..b681192 100644 --- a/R/gwalkr.R +++ b/R/gwalkr.R @@ -8,7 +8,6 @@ #' @import shiny #' @import shinycssloaders #' @import DBI -#' @import duckdb #' #' @param data A data frame to be visualized in the GWalkR. The data frame should not be empty. #' @param lang A character string specifying the language for the widget. Possible values are "en" (default), "ja", "zh". @@ -25,7 +24,7 @@ #' @param visConfig An optional config string to reproduce your chart. You can copy the string by clicking "export config" button on the GWalkR interface. #' @param visConfigFile An optional config file path to reproduce your chart. You can download the file by clicking "export config" button then "download" button on the GWalkR interface. #' @param toolbarExclude An optional list of strings to exclude the tools from toolbar UI. However, Kanaries brand info is not allowed to be removed or changed unless you are granted with special permission. -#' @param kernelComputation An optional boolean to enable the kernel mode computation which is much more efficient. Default is FALSE. +#' @param kernelComputation An optional boolean to enable the kernel mode computation which is much more efficient. Requires duckdb package installed. Default is FALSE. #' #' @return An \code{htmlwidget} object that can be rendered in R environments #' @@ -45,6 +44,10 @@ gwalkr <- function(data, lang = "en", dark = "light", columnSpecs = list(), visC if (!is.null(visConfigFile)) { visConfig <- readLines(visConfigFile, warn=FALSE) } + if (kernelComputation && !requireNamespace("duckdb", quietly = TRUE)) { + warning("The 'duckdb' package is not installed. This feature will be disabled. Please install it with install.packages('duckdb').", call. = FALSE) + kernelComputation <- FALSE + } if (kernelComputation) { gwalkr_kernel(data, lang, dark, rawFields, visConfig, toolbarExclude) diff --git a/man/gwalkr.Rd b/man/gwalkr.Rd index 0e39ca4..68423fe 100644 --- a/man/gwalkr.Rd +++ b/man/gwalkr.Rd @@ -38,7 +38,7 @@ only be one of "measure" or "dimension". \code{semanticType} can only be one of \item{toolbarExclude}{An optional list of strings to exclude the tools from toolbar UI. However, Kanaries brand info is not allowed to be removed or changed unless you are granted with special permission.} -\item{kernelComputation}{An optional boolean to enable the kernel mode computation which is much more efficient. Default is FALSE.} +\item{kernelComputation}{An optional boolean to enable the kernel mode computation which is much more efficient. Requires duckdb package installed. Default is FALSE.} } \value{ An \code{htmlwidget} object that can be rendered in R environments