Skip to content

Commit a9b12b5

Browse files
committed
add extract_df() function for turning outputs into a dataframe #54 #57
1 parent 084fd33 commit a9b12b5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

R/28_extract_df.R

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#' Extract results from `dynamics()` function as a dataframe
2+
#'
3+
#' @description #unnest results from dynamics() and turn them into a dataframe that you can bind together
4+
#' @param x Outputs from a call to dynamics(), which are a named list
5+
#'
6+
#' @return a dataframe with population trajectories, initial depletion, and bycatch levels that can be printed as a table.
7+
#' @export
8+
#'
9+
#' @examples
10+
#' x <- dynamics(S0 = 0.944, S1plus = 0.99, K1plus = 9000, AgeMat = 17, InitDepl = 0.6, ConstantCatch = NA, ConstantF = rep(0.01, times = 100), z = 2.39, nyears = 100, nages = 25, lambdaMax = 1.04)
11+
#' extract_df(x)
12+
#'
13+
extract_df <- function(x){
14+
y <- data.frame(x$trajectories)
15+
colnames(y) <- paste0("Yr_",1:ncol(y))
16+
rownames(y) <- 1:nrow(y)
17+
18+
y$sim <- 1:nrow(y)
19+
20+
y$Bycatch_Catch <- x$ConstantBycatch['Catch']
21+
y$Bycatch_CV <- x$ConstantBycatch['CV']
22+
23+
y$Bycatch_Rate <- x$ConstantRateBycatch['Rate']
24+
y$Bycatch_Rate_CV <- x$ConstantRateBycatch['CV']
25+
26+
y$InitDepl <- x$InitDepl
27+
28+
return(y)
29+
}

0 commit comments

Comments
 (0)