Skip to content
Permalink
Browse files

0.2.0.9005

  • Loading branch information...
oeysan committed Nov 3, 2018
1 parent f374f71 commit f61f437f842180add45bbc59825559e91571f4e2
@@ -1,6 +1,6 @@
Meta
.Rproj.user
.Rhistory
*.Rhistory
.RData
.Ruserdata
*.Rmd
@@ -34,27 +34,30 @@ apt_packages:
- libv8-dev

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

- testthat

notifications:
email:
on_success: change
on_failure: change

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

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

### Feature
@@ -283,6 +283,7 @@ Layout <- function(x = "a4", layout.inverse = FALSE) {
x <- switch (x,
"pt" = c(10,7.5),
"pw" = c(13.33,7.5),
"apa" = c(5.1338582677, 7.2515748),
"4a0" = c(66.2,93.6),
"2a0" = c(46.8,66.2),
"a0" = c(33.1,46.8),
@@ -459,7 +460,7 @@ Trim <- function(s, multi = TRUE) {
#' @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 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
#' @details \link[base]{strsplit}
#' @examples
@@ -515,7 +516,7 @@ VectorSub <- function ( pattern , replacement , string ) {
#' @title Tidy Code
#' @description Small function that clears up messy code
#' @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
#' @examples
#' messy <- "code <- function( x ) {
@@ -540,35 +541,47 @@ TidyCode <- function(tidy.code,
tidy.code <- gsub("model[[:space:]]+\\{", "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")

# Wrap comments prior to parsing
invisible(lapply(grep("\\#",tidy.code), function (i){
tidy.code[i] <<- sprintf("invisible(\"StartPreParse%sEndPreParse\")" , tidy.code[i])
invisible(lapply(grep("\\#",tidy.code), function (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
tidy.code <- base::parse(text = tidy.code, keep.source = FALSE)

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

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

# Revert comments (remove invisibility)
tidy.code <- gsub("invisible\\(\\\"StartPreParse" , "" , 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) {
tidy.code <- gsub("if \\(TidyJagsData\\)", "data" , tidy.code)
tidy.code <- gsub("if \\(TidyJagsModel\\)", "model" , tidy.code)
}

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

return (tidy.code)
}
@@ -594,4 +607,47 @@ ETA <- function (start.time, i , total) {
cat("\r" , eta.message , sep="")
utils::flush.console()
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)

}
Oops, something went wrong.

0 comments on commit f61f437

Please sign in to comment.
You can’t perform that action at this time.