Skip to content

Commit

Permalink
replaced calls to reshape2::melt with a custom function that uses
Browse files Browse the repository at this point in the history
`stack`
  • Loading branch information
mkoohafkan committed Jul 29, 2015
1 parent f9bf00d commit ef4c32b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ URL: https://github.com/mkoohafkan/rivr
BugReports: https://github.com/mkoohafkan/rivr/issues
License: GPL (>= 3)
Depends: R (>= 3.1.2)
Imports: Rcpp (>= 0.11.3), reshape2 (>= 1.4)
Imports: Rcpp (>= 0.11.3)
Suggests: dplyr, ggplot2, knitr
LinkingTo: Rcpp
LazyData: true
Expand Down
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by roxygen2 (4.1.0): do not edit by hand
# Generated by roxygen2 (4.1.1): do not edit by hand

export(channel_geom)
export(compute_profile)
Expand All @@ -8,5 +8,4 @@ export(froude)
export(normal_depth)
export(route_wave)
importFrom(Rcpp,evalCpp)
importFrom(reshape2,melt)
useDynLib(rivr)
1 change: 0 additions & 1 deletion R/graduallyvariedflow_v2.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#' @docType package
#' @useDynLib rivr
#' @importFrom Rcpp evalCpp
#' @importFrom reshape2 melt
NULL

check_profile = function(So, n, Q, g, Cm, B, SS, y0, stepdist){
Expand Down
14 changes: 10 additions & 4 deletions R/route_wave_v4.r
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,20 @@ route_wave = function(So, n, Cm, g, B, SS,
}
}
# extract monitor data
stackmat = function(m){
d = cbind(rid = rep(rownames(m), ncol(m)), stack(as.data.frame(m))[2:1])
d[[1]] = as.numeric(levels(d$rid))[d$rid]
d[[2]] = as.numeric(levels(d$ind))[d$ind]
d
}
mpmat = reslist[["monitorpoints"]]
mtmat = reslist[["monitortimes"]]
colnames(mpmat) = as.integer(monitor.nodes)
rownames(mpmat) = as.integer(seq(nrow(mpmat)))
colnames(mtmat) = as.integer(seq(ncol(mtmat)))
rownames(mtmat) = as.integer(monitor.times)
mpdf = melt(mpmat)
mtdf = melt(mtmat)
mpdf = stackmat(mpmat)
mtdf = stackmat(mtmat)
# add extra data
mpnames = c("mpdepth", "mpvelocity", "mparea")
mtnames= c("mtdepth", "mtvelocity", "mtarea")
Expand All @@ -170,14 +176,14 @@ route_wave = function(So, n, Cm, g, B, SS,
thismat = reslist[[n]]
colnames(thismat) = as.integer(monitor.nodes)
rownames(thismat) = as.integer(seq(nrow(thismat)))
thisdf = melt(thismat)
thisdf = stackmat(thismat)
mpdf = cbind(mpdf, thisdf[, 3])
}
for(n in mtnames){
thismat = reslist[[n]]
colnames(thismat) = as.integer(seq(ncol(thismat)))
rownames(thismat) = as.integer(monitor.times)
thisdf = melt(thismat)
thisdf = stackmat(thismat)
mtdf = cbind(mtdf, thisdf[, 3])
}
names(mpdf) = c("step", "node", "flow", addnames)
Expand Down

0 comments on commit ef4c32b

Please sign in to comment.