Skip to content

Commit

Permalink
added quarto to vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
jimianelli committed Jun 4, 2024
1 parent 49f3a0d commit fd3e2d2
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 148 deletions.
290 changes: 145 additions & 145 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,148 +1,3 @@
dat2list
old_dir <- getwd()
# Document function below that is used to run the SPM code
dirname <- "examples/atka"
setwd(dirname)
args=""
system(paste("spm",args))
read.csv("spm_detail.csv"))
read.csv("spm_detail.csv")
(tibble::tibble(read.csv("spm_detail.csv"))
)
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
# Document function below that is used to run the SPM code
dirname <- "examples/atka"
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
View(runSPM)
# Document function below that is used to run the SPM code
runSPM("examples/atka")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
# Document function below that is used to run the SPM code
runSPM("examples/atka")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
getwd()
setwd(old_dir)
getwd()
# Document function below that is used to run the SPM code
runSPM("examples/atka")
# Document function below that is used to run the SPM code
runSPM("examples/atka")
setwd(old_dir)
getwd()
# Document function below that is used to run the SPM code
runSPM("examples/atka")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
setwd(old_dir)
getwd()
dirname
setwd(dirname)
setwd(old_dir)
# Document function below that is used to run the SPM code
runSPM("examples/atka")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
# Document function below that is used to run the SPM code
runSPM("examples/atka")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
# Document function below that is used to run the SPM code
runSPM("examples/atka")
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
getwd
getwd()
setwd(old_dir)
source("~/_mymods/afsc-assessments/spmR/R/runSPM.R")
# Document function below that is used to run the SPM code
runSPM("examples/atka")
library(spmR)
df <-
runSPM("examples/atka")
df
p1<- df %>% filter(Alternative==2,SSB<500) %>% ggplot(aes(x=SSB,y=F)) + geom_point(color="salmon",alpha=.2) + theme_few()
library(tidyverse)
library(patchwork)
p1<- df %>% filter(Alternative==2,SSB<500) %>% ggplot(aes(x=SSB,y=F)) + geom_point(color="salmon",alpha=.2) + theme_few()
library(ggthemes)
p1<- df %>% filter(Alternative==2,SSB<500) %>% ggplot(aes(x=SSB,y=F)) + geom_point(color="salmon",alpha=.2) + theme_few()
p2<- df %>% filter(Alternative==2,SSB<500) %>% ggplot(aes(x=SSB,y=ABC)) + geom_point(alpha=.2,color="blue") + theme_few()
p3<- df %>% filter(Alternative==2,SSB<500) %>% ggplot(aes(x=log(SSB),y=log(Rec)/log(SSB))) + geom_point(alpha=.2,color="green",size=.5) + geom_smooth() + theme_few()
p1/p2/p3
p1<- df %>% filter(Alternative==2,) %>% ggplot(aes(x=SSB,y=F)) + geom_point(color="salmon",alpha=.2) + theme_few()
p1/p2/p3
p2<- df %>% filter(Alternative==2) %>% ggplot(aes(x=SSB,y=ABC)) + geom_point(alpha=.2,color="blue") + theme_few()
p3<- df %>% filter(Alternative==2) %>% ggplot(aes(x=log(SSB),y=log(Rec)/log(SSB))) + geom_point(alpha=.2,color="green",size=.5) + geom_smooth() + theme_few()
p1/p2/p3
pdt <- df
pdt$Alternative <- as.factor(pdt$Alternative)
names(pdt)
pt <- pdt%>%filter(Yr>2021,Alternative==2) %>% group_by(Yr,Alternative) %>% summarise(Catch=mean(Catch),ABC=mean(ABC),OFL=mean(OFL),SSB=median(SSB) ,lb=quantile(SSB,.2) ,ub=quantile(SSB,.8) )
pt
ggplot(pt,aes(x=Yr,y=SSB,fill=Alternative)) + geom_line() + mytheme + ylim(c(0,340000)) + geom_ribbon(aes(ymin=lb,ymax=ub,fill=Alternative),alpha=0.25) + labs(y="Spawning biomass (kt)",x="Year") + scale_x_continuous(breaks=seq(2022,2035,2))
mytheme<-theme_few()
ggplot(pt,aes(x=Yr,y=SSB,fill=Alternative)) + geom_line() + mytheme + ylim(c(0,340000)) + geom_ribbon(aes(ymin=lb,ymax=ub,fill=Alternative),alpha=0.25) + labs(y="Spawning biomass (kt)",x="Year") + scale_x_continuous(breaks=seq(2022,2035,2))
c1 <- ggplot(pt,aes(x=Yr,y=Catch,color=Alternative,size=1.)) + geom_line(size=1.5) + mytheme + labs(y="Catch (kt)",x="Year") + scale_x_continuous(breaks=seq(2015,2032,2))
c1 <- c1 + geom_line(aes(x=Yr,y=ABC),size=1)
#c1 <- c1 + geom_line(data=pt[as.numeric(Alternative)==2,.(Yr,ABC)],aes(x=Yr,y=ABC))
c1
pt[as.numeric(Alternative)==2,.(Yr,ABC)]
pt <- pdt[Yr>2018,.(Catch=mean(Catch),ABC=mean(ABC),OFL=mean(OFL)),.(Yr,Alternative)]
pt
ggplot(pt,aes(x=Yr,y=OFL,color=Alternative)) + geom_line() + mytheme
pdt
pdx <-rbind(pdt)
setkey(pdx,Yr,Alternative)
ggplot(pt,aes(x=Yr,y=Catch,color=config,shape=config)) + geom_line() + geom_point() + mytheme + geom_ribbon(aes(ymin=lb,ymax=ub,fill=config),alpha=0.25) + labs(x="Year")+ scale_x_continuous(breaks=seq(2015,2032,2)) + ylim(c(0,130))
library(spmR)
print_Tier3_tables(df)
df
library(spmR)
df
print_Tier3_tables(df)
source("~/_mymods/afsc-assessments/spmR/R/readData.R")
print_Tier3_tables(df)
source("~/_mymods/afsc-assessments/spmR/R/readData.R")
print_Tier3_tables(df)
print_Tier3_tables(df)
print_Tier3_tables(df) |> gt::gt()
dim(df)
df
bf<-df
# ,header=TRUE,as.is=TRUE))
# Stock Alt Sim Yr SSB Rec Tot_biom SPR_Implied F Ntot Catch ABC OFL AvgAge AvgAgeTot SexRatio FABC FOFL
bfsum <- bf %>% select(Alternative,Yr,SSB,F,ABC ,Catch) %>% group_by(Alternative,Yr) %>% summarise(Catch=mean(Catch),SSB=mean(SSB),F=mean(F),ABC=mean(ABC))
tC <- bfsum %>% select(Alternative,Yr,Catch) %>% spread(Alternative,Catch)
names(tC) <- c("Catch","Scenario 1","Scenario 2","Scenario 3","Scenario 4","Scenario 5","Scenario 6","Scenario 7")
tB <- bfsum %>% select(Alternative,Yr,SSB) %>% spread(Alternative,SSB)
names(tB) <- c("SSB","Scenario 1","Scenario 2","Scenario 3","Scenario 4","Scenario 5","Scenario 6","Scenario 7")
tF <- bfsum %>% select(Alternative,Yr,F) %>% spread(Alternative,F)
names(tF) <- c("F","Scenario 1","Scenario 2","Scenario 3","Scenario 4","Scenario 5","Scenario 6","Scenario 7")
tA <- bfsum %>% select(Alternative,Yr,ABC) %>% spread(Alternative,ABC)
names(tA) <- c("ABC","Scenario 1","Scenario 2","Scenario 3","Scenario 4","Scenario 5","Scenario 6","Scenario 7")
tab <- (data.frame(tC))
rownames(tab)<-c()
cap <- paste0("For the configuration named ",mod_names[mod_number],", ",tabcap[40])
for (i in 2:length(tab[1,]) )
mod_name="Atka base"
cap <- paste0("For the configuration named ",mod_name)
for (i in 2:length(tab[1,]) )
tab[,i] <- formatC((tab[,i]), format="d", big.mark=",")
tab <- xtable(tab, caption = cap, label=paste0("tab:",tablab[40]),digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) )
tab <- xtable::xtable(tab, caption = cap, label=paste0("tab:",tablab[40]),digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) )
tablab="Atka_base"
tab <- xtable::xtable(tab, caption = cap, label=paste0("tab:",tablab),digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) )
print(tab, caption.placement = "top",include.rownames = FALSE, sanitize.text.function = function(x){x}, scalebox=.85)
gt::gt(print(tab, caption.placement = "top",include.rownames = FALSE, sanitize.text.function = function(x){x}, scalebox=.85))
print(tab, caption.placement = "top",include.rownames = FALSE, sanitize.text.function = function(x){x}, scalebox=.85)
tab <- (data.frame(tA))
cap <- paste0("For the configuration named ",mod_name)
for (i in 2:length(tab[1,]) )
tab[,i] <- formatC(as.numeric(tab[,i]), format="d", big.mark=",")
tab <- xtable::xtable(tab, caption = cap, label=paste0("tab:",tablab),digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) )
print(tab, caption.placement = "top",include.rownames = FALSE, sanitize.text.function = function(x){x}, scalebox=.85)
tab <- (data.frame(tF))
cap <- paste0("For the configuration named ",mod_name)
for (i in 2:length(tab[1,]) )
tab[,i] <- formatC(as.numeric(tab[,i]), format="f",digits=3)
tab <- xtable::xtable(tab, caption = cap, label=paste0("tab:",tablab),digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) )
Expand Down Expand Up @@ -510,3 +365,148 @@ install.packages(c("magick", "openssl", "pdftools", "drake"))
install.packages(c("magick", "openssl", "pdftools", "drake"))
install.packages('curl', repos = 'https://jeroen.r-universe.dev')
Or enable a universe globally:
library(spmR)
?run_model
?runSPM
runSPM("examples/atka")
df <- runSPM("examples/atka")
print_Tier3_tables(df)
library(tidyverse)
print_Tier3_tables(df)
print_Tier3_tables(df) |> gt::gt
print_Tier3_tables(df) |> gt::gt()
print_Tier3_tables(df)
plotSPM()
plotSPM()
plotSPM(df)
library(patchwork)
plotSPM(df)
plotSPM(df)
library(spmR)
plotSPM(df)
df <- runSPM("examples/atka")
plotSPM(df)
p1 <- plotSPM(df)
p1$data
cat(sprintf(
'---
title: "Some title"
date: 09/01/2014
doi: %s
---
## Important links
- [Article](https://doi.org/{{< meta doi >}})
## DAG
```{r}
dag <- dagitty::dagitty(%s)
tidy_dag <- ggdag::tidy_dagitty(dag)
ggdag::ggdag_status(tidy_dag) +
ggdag::theme_dag()
```
',
doi_from_file,
dag_from_file
), file = 'index.qmd')
source("~/_mymods/afsc-assessments/spmR/R/Make_doc.R", echo=TRUE)
source("~/_mymods/afsc-assessments/spmR/R/Make_doc.R", echo=TRUE)
makeqmd()
cat(
sprintf(
'---
title: "Some title"
date: 09/01/2014
doi: %s
---
## Important links
- [Article](https://doi.org/{{< meta doi >}})
## DAG
```{r}
dag <- dagitty::dagitty(%s)
tidy_dag <- ggdag::tidy_dagitty(dag)
ggdag::ggdag_status(tidy_dag) +
ggdag::theme_dag()
```
',
doi_from_file,
dag_from_file
), file = 'index.qmd')
pak::pkg_install("dagitty")
pak::pkg_install("ggdag")
pak::pak_update()
install.packages("broom")
pak::pak_update()
?pak
makeqmd()
source("~/_mymods/afsc-assessments/spmR/R/Make_doc.R", echo=TRUE)
makeqmd()
source("~/_mymods/afsc-assessments/spmR/R/Make_doc.R", echo=TRUE)
makeqmd()
install.packages("officer")
makeqmd("10.1139/cjfas-2018-0128")
source("~/_mymods/afsc-assessments/spmR/R/Make_doc.R", echo=TRUE)
makeqmd("10.1139/cjfas-2018-0128")
source("~/_mymods/afsc-assessments/spmR/R/Make_doc.R", echo=TRUE)
makeqmd("10.1139/cjfas-2018-0128")
source("~/_mymods/afsc-assessments/spmR/R/Make_doc.R", echo=TRUE)
makeqmd("10.1139/cjfas-2018-0128")
source("~/_mymods/afsc-assessments/spmR/R/Make_doc.R", echo=TRUE)
cat(
sprintf(
'---
title: "Some title"
date: 09/01/2014
doi: %s
---
## Important links
- [Article](https://doi.org/{{< meta doi >}})
## DAG
```{r}
#dag <- dagitty::dagitty(%s)
#tidy_dag <- ggdag::tidy_dagitty(dag)
#ggdag::ggdag_status(tidy_dag) +
#ggdag::theme_dag()
plot(1:10)
```
',
#doi_from_file,
#dag_from_file
), file = 'index.qmd')
cat(
sprintf( '---
title: "Some title"
date: 09/01/2014
doi: %s
---
## Important links
- [Article](https://doi.org/{{< meta doi >}})
## DAG
```{r}
dag <- dagitty::dagitty(%s)
tidy_dag <- ggdag::tidy_dagitty(dag)
ggdag::ggdag_status(tidy_dag) +
ggdag::theme_dag()
```
',
doi_from_file,
dag_from_file
), file = 'index.qmd')
cat(
sprintf( '---
title: "Some title"
date: 09/01/2014
doi: %s
---
## Important links
- [Article](https://doi.org/{{< meta doi >}})
## DAG
```{r}
dag <- dagitty::dagitty(%s)
tidy_dag <- ggdag::tidy_dagitty(dag)
ggdag::ggdag_status(tidy_dag) +
ggdag::theme_dag()
```
',
"doi_from_file",
"dag_from_file"
), file = 'index.qmd')
quarto::quarto_render("index.qmd")
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LazyData: true
Suggests:
knitr, ggplot2,
rmarkdown
VignetteBuilder: knitr
VignetteBuilder:
quarto
RoxygenNote: 7.3.1
URL: http://afsc-assessments.github.io/spmR/
8 changes: 6 additions & 2 deletions vignettes/00-spm-example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ knitr::opts_chunk$set(

```{r setupex}
library(spmR)
library(tidyverse)
library(patchwork)
here::here()
```
Expand All @@ -34,11 +36,13 @@ This vignette demonstrates how to use these functions to run the SPM model and a
The following case studies have been applied.

## Atka mackerel
```{r atka,eval=FALSE}
```{r atka,eval=TRUE}
df <- runSPM(here::here("examples","atka"),run=FALSE)
setwd("spmR")
#setwd("spmR")
plotSPM(df)
```


## BSAI northern rock sole
```{r bsaiNRS,eval=FALSE}
df <- runSPM(here::here("examples","BSAI NRS"),run=FALSE)
Expand Down

0 comments on commit fd3e2d2

Please sign in to comment.