Skip to content

Commit

Permalink
added PVA chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
eeholmes committed Feb 9, 2019
1 parent 146fe69 commit 5249e50
Show file tree
Hide file tree
Showing 7 changed files with 2,740 additions and 1 deletion.
535 changes: 535 additions & 0 deletions Applications/PVA/Case_Study_1.Rmd

Large diffs are not rendered by default.

600 changes: 600 additions & 0 deletions Applications/PVA/Case_Study_1.Rnw

Large diffs are not rendered by default.

473 changes: 473 additions & 0 deletions Applications/PVA/PVA.Rmd

Large diffs are not rendered by default.

915 changes: 915 additions & 0 deletions Applications/PVA/PVA.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Lab-fitting-multi-ss-models/multivariate-ss.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ ggplot(pdat , aes(x = year , y = mean)) +
For these questions, use the `harborSealWA` data set in **MARSS**. The data are already logged, but you will need to remove the year column and have time going across the columns not down the rows.
```{r}
require(MARSS)
#Here is the dat to use for MARSS()
data(harborSealWA, package="MARSS")
dat <- t(harborSealWA[,2:6])
```
The sites are San Juan de Fuca (SJF 3), San Juan Islands (SJI 4), Eastern Bays (EBays 5), Puget Sound (PSnd 6) and Hood Canal (HC 7).
Expand Down
5 changes: 5 additions & 0 deletions datasets.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Datasets {-}

Public Domain Datasets

https://www.fisheries.noaa.gov/topic/recreational-fishing-data#using-the-data
211 changes: 211 additions & 0 deletions rnw_to_rmd.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
## script to convert a Rnw file to Rmd

rnw.to.rmd <- function(file){
require(stringr)
content=readLines(file)
content=str_replace_all(content, "<<","```{r ")
content=str_replace_all(content, ">>=", "}")
chaplines=which(str_detect(content, "chapter[{]"))
for(i in chaplines){
content[i]=str_replace(content[i],"\\\\chapter[{]","# ")
content[i]=str_split(content[i],"[}]")[[1]][1]
}
for(rem in c("chaptermark[{]", "label[{]chap", "end[{]example", "SweaveOpts")){
removelines=which(str_detect(content, rem))
if(length(removelines)!=0) content=content[-1*removelines]
}

seclines=which(str_detect(content, "section[{]"))
for(i in seclines){
content[i]=str_replace(content[i],"\\\\section[{]","## ")
content[i]=str_split(content[i],"[}]")[[1]][1]
}
subseclines=which(str_detect(content, "subsection[{]"))
for(i in subseclines){
content[i]=str_replace(content[i],"\\\\subsection[{]","### ")
content[i]=str_split(content[i],"[}]")[[1]][1]
}
comments=which(str_detect(content, "%%%%%%%%%%") | str_detect(content, "%~~~~~~~~~"))
if(length(comments)!=0) content=content[-1*comments]
comments=which(str_detect(content, "%[/^]"))
if(length(comments)!=0) content=content[-1*comments]
for(i in c("clearpage","renewcommand","addcontentsline","newline","exend", "exbegin")){
removelines=which(str_detect(content, i))
if(length(removelines)!=0) content=content[-1*removelines]
}
endlines=which(str_detect(content, "<<reset"))
if(length(endlines)!=0) content=content[-1*(endlines:length(content))]
#homework
hwsec=which(str_detect(content, "section[*][{]Problems"))
content[hwsec]="## Problems"
enumstart=which(str_detect(content, "begin[{]hwenumerate"))
enumend=which(str_detect(content, "end[{]hwenumerate"))
items=which(str_detect(content, "\\item"))
items=items[items>enumstart & items<enumend]
for(i in 1:length(items)){
content[items[i]]=str_replace(content[items[i]],"\\\\item", paste(i,".",sep=""))
}
#enumerate
enumstart=which(str_detect(content, "begin[{]enumerate"))
enumend=which(str_detect(content, "end[{]enumerate"))
items=which(str_detect(content, "\\item"))
items=items[items>enumstart & items<enumend]
for(i in 1:length(items)){
content[items[i]]=str_replace(content[items[i]],"\\\\item", paste(i,". ",sep=""))
}
#itemize
enumstart=which(str_detect(content, "begin[{]itemize"))
enumend=which(str_detect(content, "end[{]itemize"))
items=which(str_detect(content, "\\item"))
items=items[items>enumstart & items<enumend]
for(i in 1:length(items)){
content[items[i]]=str_replace(content[items[i]],"\\\\item", "* ")
}

#change equation labels to bookdown format
eqnlabs=which(str_detect(content,"\\\\label[{]eqn:"))
for(i in eqnlabs){
locs=str_locate(content[i],"\\\\label[{]eqn:")
locsend=str_locate_all(content[i],"[}]")[[1]]
thisend=locsend[locsend[,1]>locs[1,2]][1]
str_sub(content[i],thisend,thisend)<-")"
str_sub(content[i],locs[1,1],locs[1,2])<-"(\\#eq:"
}

#change equation refs to bookdown format
eqnrefs=which(str_detect(content, "\\\\ref[{]eqn:"))
for(i in eqnrefs){
locs=str_locate_all(content[i],"\\\\ref[{]eqn:")[[1]]
locsend=str_locate_all(content[i],"[}]")[[1]]
for(j in 1:dim(locs)[1]){
thisend=locsend[locsend[,1]>locs[j,2]][1]
str_sub(content[i],thisend,thisend)<-")"
str_sub(content[i],locs[j,1],locs[j,2])<-"\\@ref(eq:"
}
}
#change section labels to bookdown format
seclabs=which(str_detect(content,"\\\\label[{]sec:"))
for(i in seclabs){
locs=str_locate(content[i],"\\\\label[{]sec:")
str_sub(content[i],locs[1,1],locs[1,2])<-"{#sec-"
}
val1 = "\\\\ref[{]sec:"; val2="[}]"
valr1 = "\\@ref(sec-"; valr2 =")"
vals=which(str_detect(content, val1))
for(i in vals){
locs=str_locate_all(content[i],val1)[[1]]
while(nrow(locs)>0){
locsend=str_locate_all(content[i],val2)[[1]]
j=1
thisend=locsend[locsend[,1]>locs[j,2]][1]
str_sub(content[i],thisend,thisend)<-valr2
locs=str_locate_all(content[i],val1)[[1]] #REDO SINCE VALR2 IS LONGER
str_sub(content[i],locs[j,1],locs[j,2])<-valr1
locs=str_locate_all(content[i],val1)[[1]]
}
}
#change any leftoever refs to bookdown format
val1 = "\\\\ref[{]"; val2="[}]"
valr1 = "\\@ref("; valr2 =")"
vals=which(str_detect(content, val1))
for(i in vals){
locs=str_locate_all(content[i],val1)[[1]]
while(nrow(locs)>0){
locsend=str_locate_all(content[i],val2)[[1]]
j=1
thisend=locsend[locsend[,1]>locs[j,2]][1]
str_sub(content[i],thisend,thisend)<-valr2
locs=str_locate_all(content[i],val1)[[1]] #REDO SINCE VALR2 IS LONGER
str_sub(content[i],locs[j,1],locs[j,2])<-valr1
locs=str_locate_all(content[i],val1)[[1]]
}
}
val1 = "\\\\textbf[{]"; val2="[}]"
valr1 = "**"; valr2 ="**" #valr2 must be same length as val2 part in []
vals=which(str_detect(content, val1))
for(i in vals){
locs=str_locate_all(content[i],val1)[[1]]
while(nrow(locs)>0){
locsend=str_locate_all(content[i],val2)[[1]]
j=1
thisend=locsend[locsend[,1]>locs[j,2]][1]
str_sub(content[i],thisend,thisend)<-valr2
locs=str_locate_all(content[i],val1)[[1]] #REDO SINCE VALR2 IS LONGER
str_sub(content[i],locs[j,1],locs[j,2])<-valr1
locs=str_locate_all(content[i],val1)[[1]]
}
}
val1 = "\\\\citet[{]"; val2="[}]"
valr1 = "@"; valr2 =""
vals=which(str_detect(content, val1))
for(i in vals){
locs=str_locate_all(content[i],val1)[[1]]
while(nrow(locs)>0){
locsend=str_locate_all(content[i],val2)[[1]]
j=1
thisend=locsend[locsend[,1]>locs[j,2]][1]
str_sub(content[i],thisend,thisend)<-valr2
locs=str_locate_all(content[i],val1)[[1]]
str_sub(content[i],locs[j,1],locs[j,2])<-valr1
locs=str_locate_all(content[i],val1)[[1]]
}
}
val1 = "\\\\citep[{]"; val2="[}]"
valr1 = "@["; valr2 ="]"
vals=which(str_detect(content, val1))
for(i in vals){
locs=str_locate_all(content[i],val1)[[1]]
while(nrow(locs)>0){
locsend=str_locate_all(content[i],val2)[[1]]
j=1
thisend=locsend[locsend[,1]>locs[j,2]][1]
str_sub(content[i],thisend,thisend)<-valr2
locs=str_locate_all(content[i],val1)[[1]]
str_sub(content[i],locs[j,1],locs[j,2])<-valr1
locs=str_locate_all(content[i],val1)[[1]]
}
}
val1 = "\\\\verb@"; val2="@"
valr1 = "`"; valr2 ="`" #valr2 must be same length as val2 part in []
vals=which(str_detect(content, val1))
for(i in vals){
locs=str_locate_all(content[i],val1)[[1]]
while(nrow(locs)>0){
locsend=str_locate_all(content[i],val2)[[1]]
j=1
thisend=locsend[locsend[,1]>locs[j,2]][1]
str_sub(content[i],thisend,thisend)<-valr2
locs=str_locate_all(content[i],val1)[[1]]
str_sub(content[i],locs[j,1],locs[j,2])<-valr1
locs=str_locate_all(content[i],val1)[[1]]
}
}
val1 = "\\\\texttt[{]"; val2="[}]"
valr1 = "`"; valr2 ="`" #valr2 must be same length as val2 part in []
vals=which(str_detect(content, val1))
for(i in vals){
locs=str_locate_all(content[i],val1)[[1]]
while(nrow(locs)>0){
locsend=str_locate_all(content[i],val2)[[1]]
j=1
thisend=locsend[locsend[,1]>locs[j,2]][1]
str_sub(content[i],thisend,thisend)<-valr2
locs=str_locate_all(content[i],val1)[[1]]
str_sub(content[i],locs[j,1],locs[j,2])<-valr1
locs=str_locate_all(content[i],val1)[[1]]
}
}
content[content=="@"]="```"
content=str_replace_all(content, "label=", "")
content=str_replace_all(content, ", keep[.]source=TRUE", "")
content=str_replace_all(content, ",keep[.]source=TRUE", "")
content=str_replace_all(content, ", include[.]source=TRUE", "")
content=str_replace_all(content, ",include[.]source=TRUE", "")
content=str_replace_all(content, ", keep[.]source=FALSE", "")
content=str_replace_all(content, ",keep[.]source=FALSE", "")
content=str_replace_all(content, ", include[.]source=FALSE", "")
content=str_replace_all(content, ",include[.]source=FALSE", "")
content=str_replace_all(content, "=hide", "='hide'")
outfile = paste0(str_split(file,"[.]")[[1]][1],".Rmd")
cat(content, file=outfile, sep="\n")
}

0 comments on commit 5249e50

Please sign in to comment.