diff --git a/NEWS.md b/NEWS.md index a96c30f..a4642d7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,13 +2,14 @@ ## Enhancements -* Reduced the dependency of a few other packages. +* Reduce the dependency of a few other packages. * `time.range` can be defined as a R date or datetime object. +* Use the built-in data in the documentation examples (#35) ## Bug fixes * Correctly handle interval queries for databases that don't have the requested data. -* Fixed an error in `process_folder` when dplyr 0.4.2 is installed. +* Fix an error in `process_folder` when dplyr 0.4.2 is installed (#37). ## Database structure diff --git a/R/auxiliary.R b/R/auxiliary.R index 369a67d..fd61d34 100644 --- a/R/auxiliary.R +++ b/R/auxiliary.R @@ -32,10 +32,15 @@ valid_columns <- function() c("collection", "property", "name", "parent", "categ #' @param x Vector of sample values from an rplexos query #' #' @examples -#' \dontrun{db <- plexos_open()} -#' \dontrun{res <- query_month(db, "Generator", "Generation")} -#' \dontrun{res %>% filter(sample_stats(sample)) # To obtain statistics} -#' \dontrun{res %>% filter(!sample_stats(sample)) # To obtain sample results} +#' # Process the folder with the solution file provided by rplexos +#' location <- location_solution_rplexos() +#' process_folder(location) +#' +#' # Query data +#' db <- plexos_open(location) +#' res <- query_month(db, "Generator", "Generation") +#' res %>% filter(sample_stats(sample)) # To obtain statistics +#' res %>% filter(!sample_stats(sample)) # To obtain sample results #' #' @export is_sample_stats <- function(x) diff --git a/R/process_folder.R b/R/process_folder.R index b6f5c4b..a9467ca 100644 --- a/R/process_folder.R +++ b/R/process_folder.R @@ -27,8 +27,16 @@ #' @param keep.temp Should temporary databases be preserved? #' #' @examples +#' # Process the folder with the solution file provided by rplexos +#' location <- location_solution_rplexos() +#' process_folder(location) +#' +#' # Process the folder with the input file provided by rplexos +#' location2 <- location_input_rplexos() +#' process_folder(location2) +#' +#' # Other examples #' \dontrun{process_folder()} -#' \dontrun{process_folder("HiWind")} #' \dontrun{process_solution("HiWind/Model WWSIS_c_RT_CoreB_M01_SC3 Solution.zip")} #' \dontrun{process_input("WWSIS model.xml")} #' diff --git a/R/query.R b/R/query.R index 217baf3..78c1543 100644 --- a/R/query.R +++ b/R/query.R @@ -74,6 +74,16 @@ get_table_scenario <- function(db, from) { #' @seealso \code{\link{query_master}} to perform standard queries of data #' @family special queries #' +#' @examples +#' # Process the folder with the solution file provided by rplexos +#' location <- location_solution_rplexos() +#' process_folder(location) +#' +#' # Query data +#' db <- plexos_open(location) +#' query_sql(db, "SELECT * from day") +#' query_sql(db, "SELECT * from time") +#' #' @export query_sql <- function(db, sql) { # Check inputs @@ -109,7 +119,16 @@ query_sql <- function(db, sql) { #' @inheritParams query_master #' @seealso \code{\link{plexos_open}} to create the PLEXOS database object #' @family special queries -#' +#' +#' @examples +#' # Process the folder with the solution file provided by rplexos +#' location <- location_solution_rplexos() +#' process_folder(location) +#' +#' # Query data +#' db <- plexos_open(location) +#' query_property(db) +#' #' @export query_property <- function(db) { get_table_scenario(db, "property") %>% @@ -130,6 +149,15 @@ query_property <- function(db) { #' @seealso \code{\link{plexos_open}} to create the PLEXOS database object #' @family special queries #' +#' @examples +#' # Process the folder with the solution file provided by rplexos +#' location <- location_solution_rplexos() +#' process_folder(location) +#' +#' # Query data +#' db <- plexos_open(location) +#' query_config(db) +#' #' @export query_config <- function(db) { data <- get_table_scenario(db, "config") @@ -146,6 +174,16 @@ query_config <- function(db) { #' @seealso \code{\link{plexos_open}} to create the PLEXOS database object #' @family special queries #' +#' @examples +#' # Process the folder with the solution file provided by rplexos +#' location <- location_solution_rplexos() +#' process_folder(location) +#' +#' # Query data +#' db <- plexos_open(location) +#' query_log(db) +#' querty_log_steps(db) +#' #' @export query_log <- function(db) { get_table_scenario(db, "log_info") %>% @@ -227,6 +265,17 @@ query_log_steps <- function(db) { #' @seealso \code{\link{plexos_open}} to create the PLEXOS database object #' @seealso \code{\link{query_sql}} to perform custom queries #' +#' @examples +#' # Process the folder with the solution file provided by rplexos +#' location <- location_solution_rplexos() +#' process_folder(location) +#' +#' # Query data +#' db <- plexos_open(location) +#' query_day(db, "Generator", "Generation") +#' query_day(db, "Region", "*") +#' query_interval(db, "Generator", "Generation") +#' #' @export #' @importFrom data.table data.table CJ #' @importFrom foreach foreach %dopar% diff --git a/man/is_sample_stats.Rd b/man/is_sample_stats.Rd index 8650dc2..070ef69 100644 --- a/man/is_sample_stats.Rd +++ b/man/is_sample_stats.Rd @@ -14,9 +14,14 @@ In stochastic simulations, PLEXOS will return sample results and their statistic makes it easy to separate them with a filter. } \examples{ -\dontrun{db <- plexos_open()} -\dontrun{res <- query_month(db, "Generator", "Generation")} -\dontrun{res \%>\% filter(sample_stats(sample)) # To obtain statistics} -\dontrun{res \%>\% filter(!sample_stats(sample)) # To obtain sample results} +# Process the folder with the solution file provided by rplexos +location <- location_solution_rplexos() +process_folder(location) + +# Query data +db <- plexos_open(location) +res <- query_month(db, "Generator", "Generation") +res \%>\% filter(sample_stats(sample)) # To obtain statistics +res \%>\% filter(!sample_stats(sample)) # To obtain sample results } diff --git a/man/process_folder.Rd b/man/process_folder.Rd index e3a9d6e..dbe182e 100644 --- a/man/process_folder.Rd +++ b/man/process_folder.Rd @@ -44,8 +44,16 @@ Do not rename the SQLite databases created with these functions. Other code expe those filenames to remain unchanged. } \examples{ +# Process the folder with the solution file provided by rplexos +location <- location_solution_rplexos() +process_folder(location) + +# Process the folder with the input file provided by rplexos +location2 <- location_input_rplexos() +process_folder(location2) + +# Other examples \dontrun{process_folder()} -\dontrun{process_folder("HiWind")} \dontrun{process_solution("HiWind/Model WWSIS_c_RT_CoreB_M01_SC3 Solution.zip")} \dontrun{process_input("WWSIS model.xml")} } diff --git a/man/query_config.Rd b/man/query_config.Rd index b454acc..2d24bec 100644 --- a/man/query_config.Rd +++ b/man/query_config.Rd @@ -14,6 +14,15 @@ Get information from the \code{config} table, which includes: PLEXOS version, so date and time, machine and location of PLEXOS input database, model description and user name. Additionally, it stores the version of rplexos used to process the PLEXOS database. } +\examples{ +# Process the folder with the solution file provided by rplexos +location <- location_solution_rplexos() +process_folder(location) + +# Query data +db <- plexos_open(location) +query_config(db) +} \seealso{ \code{\link{plexos_open}} to create the PLEXOS database object diff --git a/man/query_log.Rd b/man/query_log.Rd index f7d3e83..64e638c 100644 --- a/man/query_log.Rd +++ b/man/query_log.Rd @@ -16,6 +16,16 @@ query_log_steps(db) During the processing of the PLEXOS databases, information from the log file is saved into the database. This includes solution times and infeasibilities for the different phases. } +\examples{ +# Process the folder with the solution file provided by rplexos +location <- location_solution_rplexos() +process_folder(location) + +# Query data +db <- plexos_open(location) +query_log(db) +querty_log_steps(db) +} \seealso{ \code{\link{plexos_open}} to create the PLEXOS database object diff --git a/man/query_master.Rd b/man/query_master.Rd index 78c027a..38554b0 100644 --- a/man/query_master.Rd +++ b/man/query_master.Rd @@ -115,6 +115,17 @@ The parameter \code{multiply.time} allows to multiply values by interval duratio doing the sum of interval data. This can be used, for example, to obtain total energy (in MWh) from power time series (in MW). } +\examples{ +# Process the folder with the solution file provided by rplexos +location <- location_solution_rplexos() +process_folder(location) + +# Query data +db <- plexos_open(location) +query_day(db, "Generator", "Generation") +query_day(db, "Region", "*") +query_interval(db, "Generator", "Generation") +} \seealso{ \code{\link{plexos_open}} to create the PLEXOS database object diff --git a/man/query_property.Rd b/man/query_property.Rd index 3b5da69..4b58b83 100644 --- a/man/query_property.Rd +++ b/man/query_property.Rd @@ -14,6 +14,15 @@ Produce a list of available properties, their units and the collections they bel Additionally, a column is created for each scenario that indicates in how many databases the property appears. } +\examples{ +# Process the folder with the solution file provided by rplexos +location <- location_solution_rplexos() +process_folder(location) + +# Query data +db <- plexos_open(location) +query_property(db) +} \seealso{ \code{\link{plexos_open}} to create the PLEXOS database object diff --git a/man/query_sql.Rd b/man/query_sql.Rd index 8d71aa3..96c4014 100644 --- a/man/query_sql.Rd +++ b/man/query_sql.Rd @@ -14,6 +14,16 @@ query_sql(db, sql) \description{ Send a SQL query to all the files in a PLEXOS database object. } +\examples{ +# Process the folder with the solution file provided by rplexos +location <- location_solution_rplexos() +process_folder(location) + +# Query data +db <- plexos_open(location) +query_sql(db, "SELECT * from day") +query_sql(db, "SELECT * from time") +} \seealso{ \code{\link{plexos_open}} to create the PLEXOS database object