Skip to content

Commit 9f00cce

Browse files
committed
initial commit: turn trajectory list into df for easy output from shiny
1 parent a9b12b5 commit 9f00cce

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

R/28_traj_list_to_df.R

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#' Turn a nested list of projections into a single dataframe
2+
#' @description This function is for any case where the user wants to pull the projection outputs out of their nested list format. In the Shiny app, it is used to generate a simple table of raw outputs in case users want to create their own plots.
3+
#' @param x A nested list of projections, with depletion levels nested within bycatch levels.
4+
#'
5+
#' @return a dataframe containing projection outputs, initial depletion levels, and bycatch levels.
6+
#' @export
7+
#'
8+
#' @examples
9+
#' parms <- list(S0 = 0.944, S1plus = 0.99, K1plus = 9000, AgeMat = 18,
10+
#' nages = 25, z = 2.39, lambdaMax = 1.02)
11+
#' nyears <- 50
12+
#' initdepl.vec <- c(0.2, 0.5, 0.9)
13+
#' high.list.const <- lapply(
14+
#' X = initdepl.vec,
15+
#' function(x) {
16+
#' projections(
17+
#' NOut = 50,
18+
#' ConstantBycatch = list(Catch = 25, CV = 0.3),
19+
#' InitDepl = x,
20+
#' lh.params = parms,
21+
#' nyears = nyears,
22+
#' obs_CV = 0.1
23+
#' )
24+
#' }
25+
#' )
26+
#' med.list.const <- lapply(
27+
#' X = initdepl.vec,
28+
#' function(x) {
29+
#' projections(
30+
#' NOut = 50,
31+
#' ConstantBycatch = list(Catch = 12, CV = 0.3),
32+
#' InitDepl = x,
33+
#' lh.params = parms,
34+
#' nyears = nyears,
35+
#' obs_CV = 0.1
36+
#' )
37+
#' }
38+
#' )
39+
#' low.list.const <- lapply(
40+
#' X = initdepl.vec,
41+
#' function(x) {
42+
#' projections(
43+
#' NOut = 50,
44+
#' ConstantBycatch = list(Catch = 2, CV = 0.3),
45+
#' InitDepl = x,
46+
#' lh.params = parms,
47+
#' nyears = nyears,
48+
#' obs_CV = 0.1
49+
#' )
50+
#' }
51+
#' )
52+
#' zero.list.const <- lapply(
53+
#' X = initdepl.vec,
54+
#' function(x) {
55+
#' projections(
56+
#' NOut = 50,
57+
#' ConstantBycatch = list(Catch = 0, CV = 0),
58+
#' InitDepl = x,
59+
#' lh.params = parms,
60+
#' nyears = nyears,
61+
#' obs_CV = 0.1
62+
#' )
63+
#' }
64+
#' )
65+
66+
#' traj.list <- list(
67+
#' high.list.const,
68+
#' med.list.const,
69+
#' low.list.const,
70+
#' zero.list.const
71+
#' )
72+
traj_list_to_df <- function(x){
73+
# x is a full list of trajectories, a nested list with depletion level nested in bycatch
74+
z <- list()
75+
for(i in 1:length(x)){
76+
y <- lapply(x[[i]], FUN = extract_df)
77+
z[[i]] <- do.call(rbind, y)
78+
}
79+
aa <- do.call(rbind, z)
80+
return(aa)
81+
}
82+

0 commit comments

Comments
 (0)