Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
achubaty committed Sep 9, 2015
2 parents 66827da + 5623869 commit 90cc73b
Show file tree
Hide file tree
Showing 49 changed files with 1,665 additions and 1,266 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
cran-comments.md
LICENSE
^_ignore$
^_push_vignettes.sh$
^travis_wait_.*\.log$
vignettes/.*_cache$
vignettes/.*\.log$
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ cran: http://cran.rstudio.com/

sudo: required

env:
global:
- secure: "KxcKSH4TFMbNMKAj6ePl4yq6SCeYQJcDkw0PMuEdImomwxqY3mP8p+GWVmNN1PKl8k7C/rgLNPAiBoJmddXMzFvGoGRWvyeER0lDN49rzNPHANF9wnMBBYN27mp98hBZlX2Vxu48M3jbmy+wRpmKKvKxTxOa8tUkt0GVEUTPeGQ="

before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- echo "options(repos = c(CRAN='http://cran.rstudio.com'))" >> ~/.Rprofile
- "chmod 755 ./_push_vignettes.sh"

r_build_args: " "

Expand Down Expand Up @@ -66,6 +71,7 @@ r_github_packages:
- jimhester/covr

after_success:
- ./_push_vignettes.sh
- Rscript -e 'library(covr); coveralls(coverage = print(package_coverage(quiet = FALSE))); devtools::session_info()'

notifications:
Expand Down
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ Description: Easily implement a variety of simulation models, with a focus on
installed with `install.packages("fastshp", repos="http://rforge.net",
type="source")`.
URL: https://github.com/PredictiveEcology/SpaDES
Version: 1.0.1
Date: 2015-08-10
Version: 1.0.2
Date: 2015-09-09
Authors@R: c(
person(c("Alex", "M"), "Chubaty", email="[email protected].ca",
person(c("Alex", "M"), "Chubaty", email="alexander.chubaty@canada.ca",
role=c("aut", "cre")),
person(c("Eliot", "J", "B"), "McIntire", email="[email protected].ca",
person(c("Eliot", "J", "B"), "McIntire", email="eliot.mcintire@canada.ca",
role=c("aut")),
person("Steve", "Cumming", email="[email protected]",
role=c("ctb")),
Expand All @@ -32,6 +32,7 @@ Suggests:
Matrix,
RColorBrewer,
rgdal,
rmarkdown,
testthat,
tkrplot
Imports:
Expand Down
14 changes: 14 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
Known issues: https://github.com/PredictiveEcology/SpaDES/issues

version 1.0.2
=============
* update maintainer's and authors' email addresses
* fix bug in `.parseModule` (#215)
* improve dependency graph & module diagram (#216)
* `simList` accessors now work with `.simList` superclass (#217)
* fix `%>%` bug in demo (#218)
* use `rmarkdown::render` for vignettes (with #219)
* improve documentation (including #219)
* reduce sizes of built vignettes (#222)
* add slot `documentation` to module metadata (see `?defineModule`) (#224)
* fix `inputs` data.frame construction in `simInit` (#225)
* various other bug fixes

version 1.0.1
=============
* no longer `attach` the simulation environment (#212)
Expand Down
40 changes: 28 additions & 12 deletions R/module-dependencies-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ removeClass("person4")
#' @slot timeunit Describes the time (in seconds) corresponding to 1.0 simulation time units.
#' Default is \code{NA}.
#'
#' @slot citation A citation for the module, as a character string. Defaults to \code{NA_character_}.
#' @slot citation A list of citations for the module, each as character strings. Alternatively, list of filenames of \code{.bib} or similar files. Defaults to \code{NA_character_}.
#'
#' @slot documentation List of filenames refering to module documentation sources.
#'
#' @slot reqdPkgs Character vector of R package names to be loaded. Defaults to \code{NA_character_}.
#'
Expand All @@ -69,24 +71,38 @@ removeClass("person4")
#' @author Alex Chubaty
#'
setClass(".moduleDeps",
slots=list(name="character", description="character", keywords="character",
childModules="character", authors="person", version="numeric_version",
slots=list(name="character", description="character",
keywords="character", childModules="character",
authors="person", version="numeric_version",
spatialExtent="Extent", timeframe="POSIXt", timeunit="ANY",
citation="list", reqdPkgs="list", parameters="data.frame",
citation="list", documentation="list",
reqdPkgs="list", parameters="data.frame",
inputObjects="data.frame", outputObjects="data.frame"),
prototype=list(name=character(), description=character(),
keywords=character(), childModules=character(),
authors=person(), version=numeric_version("0.0.0"),
spatialExtent=extent(rep(NA_real_, 4L)),
timeframe=as.POSIXlt(c(NA, NA)), timeunit=NA_real_,
citation=list(), reqdPkgs=list(),
parameters=data.frame(paramName=character(), paramClass=character(),
default=I(list()), min=numeric(), max=numeric(),
paramDesc=character()),
inputObjects=data.frame(objectName=character(), objectClass=character(),
other=character(), stringsAsFactors=FALSE),
outputObjects=data.frame(objectName=character(), objectClass=character(),
other=character(), stringsAsFactors=FALSE)),
citation=list(), documentation=list(), reqdPkgs=list(),
parameters = data.frame(
paramName=character(),
paramClass=character(),
default=I(list()), min=numeric(), max=numeric(),
paramDesc=character()
),
inputObjects = data.frame(
objectName=character(),
objectClass=character(),
other=character(),
stringsAsFactors=FALSE
),
outputObjects = data.frame(
objectName=character(),
objectClass=character(),
other=character(),
stringsAsFactors=FALSE
)
),
validity=function(object) {
if (length(object@name)!=1L) stop("name must be a single character string.")
if (length(object@description)!=1L) stop("description must be a single character string.")
Expand Down
5 changes: 4 additions & 1 deletion R/module-dependencies-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ setMethod("depsGraph",
} else {
el <- depsEdgeList(sim, plot) %>% .depsPruneEdges
}
return(graph_from_data_frame(el))
core <- c("checkpoint", "save", "progress", "load")
m <- modules(sim) %>% unlist
v <- unique(c(el$to, el$from, m[-which(m %in% core)]))
return(graph_from_data_frame(el, vertices=v, directed=TRUE))
})

#' @export
Expand Down
71 changes: 56 additions & 15 deletions R/module-template.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
#' @return Nothing is returned. The new module file is created at \code{path/name.R}, as
#' well as anciliary files for documentation, citation, license, and readme.
#'
#' @note On Windows there is currently a bug in RStudio that it doesn't know what editor
#' to open with \code{file.edit} is called (which is what moduleName does). This will return an error:
#'
#' \code{Error in editor(file = file, title = title) :}
#' \code{argument "name" is missing, with no default}
#'
#' You can just browse to the file and open it manually.
#'
#' @export
#' @docType methods
#' @rdname newModule
Expand Down Expand Up @@ -57,13 +65,17 @@ defineModule(sim, list(
version=numeric_version(\"0.0.0\"),
spatialExtent=raster::extent(rep(NA_real_, 4)),
timeframe=as.POSIXlt(c(NA, NA)),
timeunit=NA_character_, # e.g., \"year\"
citation=list(),
timeunit=NA_character_, # e.g., \"year,\",
citation=list(\"citation.bib\"),
documentation=list(\"README.txt\", \"", name, ".Rmd\"),
reqdPkgs=list(),
parameters=rbind(
defineParameter(\".plotInitialTime\", \"numeric\", NA, NA, NA, \"This describes the simulation time at which the first plot event should occur\"),
defineParameter(\".saveInitialTime\", \"numeric\", NA, NA, NA, \"This describes the simulation time at which the first save event should occur\")),
#defineParameter(\"paramName\", \"paramClass\", value, min, max, \"parameter description\")),
defineParameter(\".plotInitialTime\", \"numeric\", NA, NA, NA, \"This describes the simulation time at which the first plot event should occur\"),
defineParameter(\".plotInterval\", \"numeric\", NA, NA, NA, \"This describes the simulation time at which the first plot event should occur\"),
defineParameter(\".saveInitialTime\", \"numeric\", NA, NA, NA, \"This describes the simulation time at which the first save event should occur\"),
defineParameter(\".saveInterval\", \"numeric\", NA, NA, NA, \"This describes the simulation time at which the first save event should occur\")
),
inputObjects=data.frame(objectName=NA_character_, objectClass=NA_character_, other=NA_character_, stringsAsFactors=FALSE),
outputObjects=data.frame(objectName=NA_character_, objectClass=NA_character_, other=NA_character_, stringsAsFactors=FALSE)
))
Expand All @@ -86,16 +98,27 @@ doEvent.", name, " = function(sim, eventTime, eventType, debug=FALSE) {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
#Plot(objectFromModule) # uncomment this, replace with object to plot
# schedule future event(s)
# e.g.,
#sim <- scheduleEvent(sim, params(sim)$", name, "$.plotInitialTime, \"", name, "\", \"plot\")
# ! ----- STOP EDITING ----- ! #
} else if (eventType==\"save\") {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
# e.g., call your custom functions/methods here
# you can define your own methods below this `doEvent` function
# schedule future event(s)
# e.g.,
# sim <- scheduleEvent(sim, time(sim) + increment, \"", name, "\", \"plot\")
# sim <- scheduleEvent(sim, time(sim) + increment, \"", name, "\", \"save\")
# ! ----- STOP EDITING ----- ! #
} else if (eventType==\"save\") {
} else if (eventType==\"event1\") {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
Expand All @@ -105,10 +128,10 @@ doEvent.", name, " = function(sim, eventTime, eventType, debug=FALSE) {
# schedule future event(s)
# e.g.,
# sim <- scheduleEvent(sim, time(sim) + increment, \"", name, "\", \"save\")
# sim <- scheduleEvent(sim, time(sim) + increment, \"", name, "\", \"templateEvent\")
# ! ----- STOP EDITING ----- ! #
} else if (eventType==\"templateEvent\") {
} else if (eventType==\"event2\") {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
Expand All @@ -121,10 +144,10 @@ doEvent.", name, " = function(sim, eventTime, eventType, debug=FALSE) {
# sim <- scheduleEvent(sim, time(sim) + increment, \"", name, "\", \"templateEvent\")
# ! ----- STOP EDITING ----- ! #
} else {
warning(paste(\"Undefined event type: \'\", events(sim)[1, \"eventType\", with=FALSE],
\"\' in module \'\", events(sim)[1, \"moduleName\", with=FALSE], \"\'\", sep=\"\"))
}
} else {
warning(paste(\"Undefined event type: \'\", events(sim)[1, \"eventType\", with=FALSE],
\"\' in module \'\", events(sim)[1, \"moduleName\", with=FALSE], \"\'\", sep=\"\"))
}
return(invisible(sim))
}
Expand Down Expand Up @@ -176,7 +199,7 @@ doEvent.", name, " = function(sim, eventTime, eventType, debug=FALSE) {
}
### template for your event2
sim$", name, "Event2 = function(sim) {
", name, "Event2 = function(sim) {
# ! ----- EDIT BELOW ----- ! #
Expand Down Expand Up @@ -389,6 +412,14 @@ setMethod("newModuleDocumentation",
#'
#' @return Nothing is returned. All file are open via \code{file.edit}.
#'
#' @note On Windows there is currently a bug in RStudio that it doesn't know what editor to
#' open with \code{file.edit} is called (which is what moduleName does). This will return an error:
#'
#' \code{Error in editor(file = file, title = title) :}
#' \code{argument "name" is missing, with no default}
#'
#' You can just browse to the file and open it manually.
#'
#' @export
#' @docType methods
#' @rdname openModules
Expand Down Expand Up @@ -485,7 +516,7 @@ definition = function(name, path, version, ...) {
on.exit(setwd(callingWd))
setwd(path)
zipFileName=paste0(name, "_", version, ".zip")
print(paste("Zipping module into zip file"))
print(paste("Zipping module into zip file:", zipFileName))
zip(zipFileName, files=file.path(name), extras=c("-x","*.zip"), ...)
file.copy(zipFileName, to=paste0(name, "/", zipFileName), overwrite=TRUE)
file.remove(zipFileName)
Expand All @@ -504,5 +535,15 @@ setMethod("zipModule",
setMethod("zipModule",
signature=c(name="character", path="missing", version="missing"),
definition = function(name, ...) {
zipModule(name=name, path=".", version="0.0.0", ...)
vers <- moduleMetadata(name, ".")$version %>% as.character
zipModule(name=name, path=".", version=vers, ...)
})

#' @export
#' @rdname zipModule
setMethod("zipModule",
signature=c(name="character", path="character", version="missing"),
definition = function(name, path, ...) {
vers <- moduleMetadata(name, path)$version %>% as.character
zipModule(name=name, path=path, version=vers, ...)
})
57 changes: 31 additions & 26 deletions R/plotting-diagrams.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ setMethod(".sim2gantt",
#' Each module appears in a color-coded row, within which each event for that
#' module is displayed corresponding to the sequence of events for that module.
#' Note that only the start time of the event is meaningful is these figures:
#' the width of the bar associated with a particular module's event corresponds
#' to the module's timeunit, not the event's "duration".
#' the width of the bar associated with a particular module's event DOES NOT
#' correspond to an event's "duration".
#'
#' Based on this StackOverflow answer: \url{http://stackoverflow.com/a/29999300/1380598}.
#'
Expand All @@ -133,7 +133,7 @@ setMethod(".sim2gantt",
#' @param ... Additional arguments passed to \code{mermaid}.
#' Useful for specifying \code{height} and \code{width}.
#'
#' @return Plots an event diagram as Gantt Chart.
#' @return Plots an event diagram as Gantt Chart, invisibly returning a \link{mermaid} object.
#'
#' @seealso \code{\link{mermaid}}.
#'
Expand Down Expand Up @@ -163,30 +163,35 @@ setMethod("eventDiagram",
}
ll <- .sim2gantt(sim, n, startDate, dots$width)

#remove progress bar events
# remove progress bar events
ll <- ll[names(ll)!="progress"]

# estimate the height of the diagram
dots$height <- if(any(grepl(pattern="height", names(dots)))) {
as.numeric(dots$height)
} else {
sapply(ll, NROW) %>% sum %>% `*`(., 26L)
}
if (length(ll)) {
# estimate the height of the diagram
dots$height <- if(any(grepl(pattern="height", names(dots)))) {
as.numeric(dots$height)
} else {
sapply(ll, NROW) %>% sum %>% `*`(., 26L)
}

diagram <- paste0(
# mermaid "header"
"gantt", "\n",
"dateFormat YYYY-MM-DD", "\n",
"title SpaDES event diagram", "\n",
diagram <- paste0(
# mermaid "header"
"gantt", "\n",
"dateFormat YYYY-MM-DD", "\n",
"title SpaDES event diagram", "\n",

# mermaid "body"
paste("section ", names(ll), "\n", lapply(ll, function(df) {
paste0(df$task, ":", df$status, ",",
df$pos, ",", df$start, ",", df$end,
collapse = "\n")
}), collapse = "\n"), "\n"
)
do.call(mermaid, args=append(diagram, dots))
# mermaid "body"
paste("section ", names(ll), "\n", lapply(ll, function(df) {
paste0(df$task, ":", df$status, ",",
df$pos, ",", df$start, ",", df$end,
collapse = "\n")
}), collapse = "\n"), "\n"
)
do.call(mermaid, args=append(diagram, dots))
} else {
stop("Unable to create eventDiagram for a simulation that hasn't been run.\n",
"Run your simulation using `mySim <- spades(mySim)` and try again.")
}
})

#' @export
Expand All @@ -210,7 +215,7 @@ setMethod("eventDiagram",
#' @param ... Additional arguments passed to \code{mermaid}.
#' Useful for specifying \code{height} and \code{width}.
#'
#' @return Plots a sequence diagram.
#' @return Plots a sequence diagram, invisibly returning a \link{mermaid} object.
#'
#' @seealso \code{\link{mermaid}}.
#'
Expand Down Expand Up @@ -258,7 +263,7 @@ setMethod("objectDiagram",
#' or \code{"tk"} for \code{igraph::tkplot}. Default missing, which uses regular
#' \code{plot}.
#'
#' @param ... Additional arguments passed to \code{plot}.
#' @param ... Additional arguments passed to plotting function specfied by \code{type}.
#'
#' @return Plots module dependency diagram.
#'
Expand Down Expand Up @@ -295,4 +300,4 @@ setMethod("moduleDiagram",
signature=c(sim="simList", type="missing"),
definition=function(sim, type, ...) {
plot(depsGraph(sim, TRUE), ...)
})
})
Loading

0 comments on commit 90cc73b

Please sign in to comment.