Skip to content

Commit

Permalink
Update examples (close #35)
Browse files Browse the repository at this point in the history
  • Loading branch information
eibanez committed Jun 10, 2015
1 parent d2b222f commit f3b37b1
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 13 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions R/auxiliary.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion R/process_folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
#'
Expand Down
51 changes: 50 additions & 1 deletion R/query.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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") %>%
Expand All @@ -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")
Expand All @@ -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") %>%
Expand Down Expand Up @@ -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%
Expand Down
13 changes: 9 additions & 4 deletions man/is_sample_stats.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

10 changes: 9 additions & 1 deletion man/process_folder.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
}
Expand Down
9 changes: 9 additions & 0 deletions man/query_config.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions man/query_log.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions man/query_master.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions man/query_property.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions man/query_sql.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f3b37b1

Please sign in to comment.