Skip to content

Commit

Permalink
0.2.0.9005
Browse files Browse the repository at this point in the history
  • Loading branch information
oeysan committed Nov 3, 2018
1 parent f374f71 commit f61f437
Show file tree
Hide file tree
Showing 51 changed files with 865 additions and 503 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,6 +1,6 @@
Meta Meta
.Rproj.user .Rproj.user
.Rhistory *.Rhistory
.RData .RData
.Ruserdata .Ruserdata
*.Rmd *.Rmd
Expand Down
11 changes: 7 additions & 4 deletions .travis.yml
Expand Up @@ -34,27 +34,30 @@ apt_packages:
- libv8-dev - libv8-dev


r_packages: r_packages:
- coda - covr
- MASS - circlize
- runjags - dplyr
- ggplot2 - ggplot2
- knitr - knitr
- lavaan - lavaan
- magrittr
- officer - officer
- plyr - plyr
- png - png
- psych - psych
- rmarkdown - rmarkdown
- rvg - rvg
- scales - scales

- testthat

notifications: notifications:
email: email:
on_success: change on_success: change
on_failure: change on_failure: change


r_github_packages: r_github_packages:
- r-lib/covr - r-lib/covr
- r-lib/devtools


after_success: after_success:
- Rscript -e 'covr::coveralls()' - Rscript -e 'covr::coveralls()'
Expand Down
8 changes: 5 additions & 3 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: bfw Package: bfw
Version: 0.2.0.9004 Version: 0.2.0.9005
Date: 2018-09-18 Date: 2018-11-03
Title: Bayesian Framework for Computational Modeling Title: Bayesian Framework for Computational Modeling
Authors@R: person( "Øystein Olav","Skaar", email="bayesianfw@gmail.com", role=c("aut","cre")) Authors@R: person( "Øystein Olav","Skaar", email="bayesianfw@gmail.com", role=c("aut","cre"))
Maintainer: Øystein Olav Skaar <bayesianfw@gmail.com> Maintainer: Øystein Olav Skaar <bayesianfw@gmail.com>
Expand All @@ -19,13 +19,15 @@ SystemRequirements: JAGS >=4.3.0 <http://mcmc-jags.sourceforge.net/>,
Depends: R (>= 3.5.0), Depends: R (>= 3.5.0),
Imports: coda (>= 0.19-1), Imports: coda (>= 0.19-1),
MASS (>= 7.3-47), MASS (>= 7.3-47),
runjags (>= 2.0.4-2) runjags (>= 2.0.4-2)
Suggests: Suggests:
covr (>= 3.1.0), covr (>= 3.1.0),
circlize (>= 0.4.4), circlize (>= 0.4.4),
dplyr (>= 0.7.7),
ggplot2 (>= 2.2.1), ggplot2 (>= 2.2.1),
knitr (>= 1.20), knitr (>= 1.20),
lavaan (>= 0.6-1), lavaan (>= 0.6-1),
magrittr (>= 1.5),
officer (>= 0.3.1), officer (>= 0.3.1),
plyr (>= 1.8.4), plyr (>= 1.8.4),
png (>= 0.1-7), png (>= 0.1-7),
Expand Down
5 changes: 4 additions & 1 deletion NAMESPACE
Expand Up @@ -15,16 +15,18 @@ export(Interleave)
export(Layout) export(Layout)
export(MatrixCombn) export(MatrixCombn)
export(MergeMCMC) export(MergeMCMC)
export(MultiGrep)
export(Normalize) export(Normalize)
export(PadVector) export(PadVector)
export(ParseNumber) export(ParseNumber)
export(ParsePlot) export(ParsePlot)
export(PlotCirclize) export(PlotCirclize)
export(PlotData)
export(PlotMean) export(PlotMean)
export(PlotNominal) export(PlotNominal)
export(PlotParam)
export(ReadFile) export(ReadFile)
export(RemoveEmpty) export(RemoveEmpty)
export(RemoveGarbage)
export(RemoveSpaces) export(RemoveSpaces)
export(RunContrasts) export(RunContrasts)
export(RunMCMC) export(RunMCMC)
Expand Down Expand Up @@ -79,6 +81,7 @@ importFrom(runjags,run.jags)
importFrom(runjags,runjags.options) importFrom(runjags,runjags.options)
importFrom(stats,acf) importFrom(stats,acf)
importFrom(stats,aggregate) importFrom(stats,aggregate)
importFrom(stats,approx)
importFrom(stats,approxfun) importFrom(stats,approxfun)
importFrom(stats,complete.cases) importFrom(stats,complete.cases)
importFrom(stats,cor) importFrom(stats,cor)
Expand Down
25 changes: 25 additions & 0 deletions NEWS.md
@@ -1,3 +1,28 @@
# bfw 0.2.0.9005

### Feature

* Updated `CFA` function to include correlation matrix
* Added a option to run `PPP` for every kth length of MCMC chains (Default is every 10th)

#### Moderate

* Optimized `RunContrasts` to allow larger MCMC simulations (2nd review)

#### Minor

* Fixed `plot_data` vignette
* Updated `README`
* Fixed title bug in `circlize` plots
* Added `RemoveGarbage` function to clear up working memory
* Added `MultiGrep` function to use multiple patterns to select an element from a vector
* Fixed bug in `kappa` function
* Fixed bug in `covariate` function
* Fixed inlinde comment bug in `TidyCode` function
* Added option to define which parameters to use for diagnostics
* Removed (some of the...) unnecessary arguments in `bfw` function
* Added a `apa` PowerPoint template

# bfw 0.2.0.9004 # bfw 0.2.0.9004


### Feature ### Feature
Expand Down
80 changes: 68 additions & 12 deletions R/basic_functions.R
Expand Up @@ -283,6 +283,7 @@ Layout <- function(x = "a4", layout.inverse = FALSE) {
x <- switch (x, x <- switch (x,
"pt" = c(10,7.5), "pt" = c(10,7.5),
"pw" = c(13.33,7.5), "pw" = c(13.33,7.5),
"apa" = c(5.1338582677, 7.2515748),
"4a0" = c(66.2,93.6), "4a0" = c(66.2,93.6),
"2a0" = c(46.8,66.2), "2a0" = c(46.8,66.2),
"a0" = c(33.1,46.8), "a0" = c(33.1,46.8),
Expand Down Expand Up @@ -459,7 +460,7 @@ Trim <- function(s, multi = TRUE) {
#' @param sep symbol to separate data (e.g., comma-delimited), Default: ',' #' @param sep symbol to separate data (e.g., comma-delimited), Default: ','
#' @param fixed logical, if TRUE match split exactly, otherwise use regular expressions. Has priority over perl, Default: FALSE #' @param fixed logical, if TRUE match split exactly, otherwise use regular expressions. Has priority over perl, Default: FALSE
#' @param perl logical, indicating whether or not to use Perl-compatible regexps, Default: FALSE #' @param perl logical, indicating whether or not to use Perl-compatible regexps, Default: FALSE
#' @param useBytes logical. If TRUE the matching is done byte-by-byte rather than character-by-character, Default: FALSE #' @param useBytes logical, if TRUE the matching is done byte-by-byte rather than character-by-character, Default: FALSE
#' @param rm.empty logical. indicating whether or not to remove empty elements, Default: TRUE #' @param rm.empty logical. indicating whether or not to remove empty elements, Default: TRUE
#' @details \link[base]{strsplit} #' @details \link[base]{strsplit}
#' @examples #' @examples
Expand Down Expand Up @@ -515,7 +516,7 @@ VectorSub <- function ( pattern , replacement , string ) {
#' @title Tidy Code #' @title Tidy Code
#' @description Small function that clears up messy code #' @description Small function that clears up messy code
#' @param tidy.code Messy code that needs cleaning #' @param tidy.code Messy code that needs cleaning
#' @param jags logical. If TRUE run code as JAGS model, Default: TRUE #' @param jags logical, if TRUE run code as JAGS model, Default: TRUE
#' @return (Somewhat) tidy code #' @return (Somewhat) tidy code
#' @examples #' @examples
#' messy <- "code <- function( x ) { #' messy <- "code <- function( x ) {
Expand All @@ -540,35 +541,47 @@ TidyCode <- function(tidy.code,
tidy.code <- gsub("model[[:space:]]+\\{", "if (TidyJagsModel) {" , tidy.code) tidy.code <- gsub("model[[:space:]]+\\{", "if (TidyJagsModel) {" , tidy.code)
tidy.code <- gsub("model\\{", "if (TidyJagsModel) {" , tidy.code) tidy.code <- gsub("model\\{", "if (TidyJagsModel) {" , tidy.code)
} }

# Extract blocks from cod # Extract blocks from code
tidy.code <- TrimSplit(tidy.code,"\\\n") tidy.code <- TrimSplit(tidy.code,"\\\n")

# Wrap comments prior to parsing # Wrap comments prior to parsing
invisible(lapply(grep("\\#",tidy.code), function (i){ invisible(lapply(grep("\\#",tidy.code), function (i) {
tidy.code[i] <<- sprintf("invisible(\"StartPreParse%sEndPreParse\")" , tidy.code[i]) if (substring(tidy.code[[i]], 1, 1) == "#") {
tidy.code[i] <<- sprintf("invisible(\"StartPreParse%sEndPreParse\")" , tidy.code[i])
} else {
tidy.code[i] <<- sprintf("%s\ninvisible(\"StartInlinePreParse%sEndPreParse\")" ,
gsub('\\#.*', '', tidy.code[[i]]),
gsub('.*\\#', '#', tidy.code[[i]]) )
}
})) }))

# Parse code # Parse code
tidy.code <- base::parse(text = tidy.code, keep.source = FALSE) tidy.code <- base::parse(text = tidy.code, keep.source = FALSE)

# Collapse parsed function into a vector # Collapse parsed function into a vector
tidy.code <- sapply(tidy.code, function(e) { tidy.code <- sapply(tidy.code, function(e) {
paste(base::deparse(e, getOption("width")), collapse = "\n") paste(base::deparse(e, getOption("width")), collapse = "\n")
}) })

# remove spaces between commas # remove spaces between commas
tidy.code <- gsub("\\s*\\,\\s*", "," , tidy.code) tidy.code <- gsub("\\s*\\,\\s*", "," , tidy.code)

# Revert comments (remove invisibility) # Revert comments (remove invisibility)
tidy.code <- gsub("invisible\\(\\\"StartPreParse" , "" , tidy.code) tidy.code <- gsub("invisible\\(\\\"StartPreParse" , "" , tidy.code)
tidy.code <- gsub("EndPreParse\\\")" , "" , tidy.code) tidy.code <- gsub("EndPreParse\\\")" , "" , tidy.code)

# Revert inline comments (remove invisibility)
tidy.code <- gsub("\n[[:space:]]+invisible\\(\\\"StartInlinePreParse" , " " , tidy.code)


# If jags replace placeholder # If jags replace placeholder
if (jags) { if (jags) {
tidy.code <- gsub("if \\(TidyJagsData\\)", "data" , tidy.code) tidy.code <- gsub("if \\(TidyJagsData\\)", "data" , tidy.code)
tidy.code <- gsub("if \\(TidyJagsModel\\)", "model" , tidy.code) tidy.code <- gsub("if \\(TidyJagsModel\\)", "model" , tidy.code)
} }

# Collapse to string
tidy.code <- paste0(tidy.code, collapse="\n")


return (tidy.code) return (tidy.code)
} }
Expand All @@ -594,4 +607,47 @@ ETA <- function (start.time, i , total) {
cat("\r" , eta.message , sep="") cat("\r" , eta.message , sep="")
utils::flush.console() utils::flush.console()
if (i == total) cat("\n") if (i == total) cat("\n")
}

#' @title Remove Garbage
#' @description Remove variable(s) and remove garbage from memory
#' @param v variables to remove
#' @rdname RemoveGarbage
#' @export

RemoveGarbage <- function (v) {
v <- TrimSplit(v)
rm( list = v, envir=sys.frame(-1) )
# Garbage Collection
invisible(base::gc(verbose = FALSE, full = TRUE))
}

#' @title Multi Grep
#' @description Use multiple patterns from vector to find element in another vector, with option to remove certain patterns
#' @param find vector to find
#' @param from vector to find from
#' @param remove variables to remove, Default: NULL
#' @param value logical, if TRUE returns value, Default: TRUE
#' @rdname MultiGrep
#' @export

MultiGrep <- function (find, from , remove = NULL , value = TRUE) {

find <- TrimSplit(find)
remove <- TrimSplit(remove)

found <- grep(paste(sprintf("(?=.*%s)",find), collapse=""),
from, perl = TRUE , value=value)

if (length(remove)) {
remove.find <- if (value) found else from[found]
remove <- unique(unlist(lapply(remove, function (x) {
grep(paste(sprintf("(?=.*\\b%s\\b)",x), collapse=""),
remove.find, perl = TRUE)
})))
found <- found[-remove]
}

return (found)

} }

0 comments on commit f61f437

Please sign in to comment.