Skip to content

Commit

Permalink
Error when combining sources with > 9 sources
Browse files Browse the repository at this point in the history
Fixed grep call to add ",". Cases with source numbers 10, 11, 12... were being combined with the source # 1, and causing errors in combine_sources and summary_stats output tables
  • Loading branch information
ericward-noaa authored Jan 24, 2020
1 parent 2b1b254 commit 4e06aea
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/combine_sources.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ combine_sources <- function(jags.1, mix, source, alpha.prior=1, groups){
for(f1 in 1:mix$FAC[[1]]$levels){
new.fac1.tmp <- matrix(NA, nrow=n.draws, ncol=source.new$n.sources)
colnames(new.fac1.tmp) <- paste0("p.fac1[",f1,",",1:source.new$n.sources,"]")
old.fac1.tmp <- post.mat[,grep(paste0("p.fac1\\[",f1), colnames(post.mat))]
old.fac1.tmp <- post.mat[,grep(paste0("p.fac1\\[",f1,","), colnames(post.mat))]
for(i in 1:source.new$n.sources){
old <- groups[[i]]
old.levels <- match(old, source$source_names)
Expand All @@ -99,7 +99,7 @@ combine_sources <- function(jags.1, mix, source, alpha.prior=1, groups){
for(f2 in 1:mix$FAC[[2]]$levels){
new.fac2.tmp <- matrix(NA, nrow=n.draws, ncol=source.new$n.sources)
colnames(new.fac2.tmp) <- paste0("p.fac2[",f2,",",1:source.new$n.sources,"]")
old.fac2.tmp <- post.mat[,grep(paste0("p.fac2\\[",f2), colnames(post.mat))]
old.fac2.tmp <- post.mat[,grep(paste0("p.fac2\\[",f2,","), colnames(post.mat))]
for(i in 1:source.new$n.sources){
old <- groups[[i]]
old.levels <- match(old, source$source_names)
Expand Down

1 comment on commit 4e06aea

@brianstock
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thank you Eric for tracking that down and fixing it!

Please sign in to comment.