Load Libraries

This file is essentially the example file included in the buildReport() function. The raw vignette script for this can be found here and the example script can be found here.

From run file:

cnt_chapt <- "000" # Keep everything in a proper order
cnt_chapt_content <- 0
cnt_equations <- 0
cnt_tables <- 0
cnt_figures <- 0
list_equations <- list()
list_tables <- list()
list_figures <- list()
dir_out_figures <- dir_out_tables <- NULL # I dont actually want to save them in this example
filename0<-"example"
indesign_flowin<-FALSE # not going into a final publication that requires indesign for final touches

Example of how to use this R Markdown document

# example data
dat <- data.frame(x = rnorm(n = 100), 
                  y = rnorm(n = 100), 
                  col = rep_len(x = c("a", "b"), length.out = 5))

Footnotes.list<-list("ExOfStandardFt" = "Wow, this project is so cool!")

types_of_vessels <- c("NOAA Vessel", "F/V Fishing Boat", "R/V University Vessel", "Private Charter")

Here is the report content:

Systematic writing of content

My example dataset has 100 rows in it and three columns in it.1

This sentence exemplifies how to systematically calculate a percent change: a 97% decrease2.

Here are several types of vessels: NOAA Vessel, F/V Fishing Boat, R/V University Vessel, and Private Charter.

Equations

Here is some equations you’ll need to have in this report:

equation = "c^2 = b^2 + a^2"
nickname = "pythagorean"
header = "Pythagorean theorem"
footnote = "footnote about how cool the pythagorean theorem is."
alttext = "The Pythagoras theorem is a mathematical law that states that the sum of squares of the lengths of the two short sides of the right triangle is equal to the square of the length of the hypotenuse."
  
# save yo' stuff and do a lot of behind the scenes work
# alt: check out the "child = " in this next chunk header (which must stay empty)
# ```{r, child = system.file("rmd/_child_save_eq.Rmd", package = "NMFSReports")}

# ```

Equation 1. Pythagorean theorem.3

\[c^2 = b^2 + a^2\]

Alternative text: The Pythagoras theorem is a mathematical law that states that the sum of squares of the lengths of the two short sides of the right triangle is equal to the square of the length of the hypotenuse.

[Text blah blah]

equation = "F = G \\frac {m_1 m_2}{d^2}"
nickname = "Newton"
header = "Newton's Universal Law of Gravitation"

# save yo' stuff and do a lot of behind the scenes work
# alt: this does the same thing as calling "child = " in the chunk header
res <- knitr::knit_child(
  text = knitr::knit_expand(
    file = system.file("rmd/_child_save_eq.Rmd", package = "NMFSReports") ), 
  quiet = TRUE
)
# `r res `

Equation 2. Newton’s Universal Law of Gravitation.

\[F = G \frac {m_1 m_2}{d^2}\]

Alternative text: Newton’s Universal Law of Gravitation

Remember the pythagorean theorem from before? That was Equation #1 and it had a footnote that said “footnote about how cool the pythagorean theorem is.”.

Citations

There are a lot of ways to cite within your report and here is an example of two: (Fry 1957) and Arrhenius (1889). Checkout https://github.com/cboettig/knitcitations for more info! For this method, you’ll need a .bib file that will be used in the YAML of the RMarkdown document. If you are an EndNote, as I am, you can export .bib files using these guides.

Note that references will appear at the bottom of this document (and any document that you put references in) but when you combine this document with all of the other documents that you create, it will shift to the bottom of the report.

Example Figure (Plot)

header <- "Here is a figure!"
footnote<-c("A footnote for this figure!", "A second footnote for this figure!")
nickname <- "ex_plot"
alttext <- "This is a scatter plot of random data."
  
# Select data and make plot
figure <- dat %>%
  ggplot(aes(x = x, y = y, colour = as.factor(col))) + # create plot
  geom_point() 

# save yo' stuff and do a lot of behind the scenes work
# alt: check out the "child = " in this next chunk header (which must stay empty)
# ```{r, child = system.file("rmd/_child_save_fig.Rmd", package = "NMFSReports")}
# ```
#> NULL
Figure 1. – Here is a figure!

Here in plot 1, we see that…

Example Figure (Reference Image)


header <- "Here is a figure!"
footnote<-c("A footnote for this figure!")
nickname <- "noaalogo"
filename_desc <- "noaalogo"
alttext <- "The NOAA Meatball and text. "

# Select data and make plot
figure <- 
  cowplot::ggdraw() +
  cowplot::draw_image(readPNG(system.file("img/NOAA_Fisheries_logo_vertical.png", package = "NMFSReports")) )

# save yo' stuff and do a lot of behind the scenes work
# alt: this does the same thing as calling "child = " in the chunk header
res <- knitr::knit_child(
  text = knitr::knit_expand(
    file = system.file("rmd/_child_save_fig.Rmd", package = "NMFSReports")), 
  quiet = TRUE
)
# `r res `
#> NULL
Figure . – Here is a figure!

Here in figure 2, we see the NOAA logo.

Example Table (Basic)

Here, we use the function theme_flextable_nmfstm which mimics many of the NMFS report tech memo motifs.


header <- "Here is a table!"
footnote<-"A footnote for this table!"
nickname <- "ex_table" # this is so you can refer to it later systematically
alttext <- "This is a 3-column table of random letters (in the first column) and numbers (in the second and third columns). "

# Select data and make plot

# Create data-saver version of table that will be used to reference things later saved as backup
table_raw<-data.frame(col = LETTERS[1:10], 
                      x = rnorm(n = 10), 
                      y = rnorm(n = 10)) 

# Create pretty version of table that will go into report
table_print <- table_raw
table_print[,c("x", "y")] <- 
  NMFSReports::mod_number(table_print[,c("x", "y")], 
                          divideby = 1, 
                          comma_seperator = TRUE, 
                          digits = 2)

table_print <- flextable::flextable(table_print) %>% 
    NMFSReports::theme_flextable_nmfstm(x = .)

# save yo' stuff and do a lot of behind the scenes work
# alt: check out the "child = " in this chunk header (which must stay empty)
# ```{r, child = system.file("rmd/_child_save_tab.Rmd", package = "NMFSReports")}
# ```

Here in table 1, we see that…

Example Table (With Footnotes)


header <- "Here is a table!"
nickname <- "ex_table_foot" # this is so you can refer to it later systematically

# Select data and make plot

# Create data-saver version of table that will be used to reference things later saved as backup
table_raw<-data.frame(col = LETTERS[1:10], 
                      x = rnorm(n = 10), 
                      y = rnorm(n = 10), 
                      footnotes = NA) 

table_raw$footnotes[3]<-"Example footnote in a table 1."
table_raw$footnotes[4]<-"Example footnote in a table 2.,,,Example footnote in a table 3."

footnote<-"A table with footnotes!"
footnote<-c(footnote, 
            ifelse(NMFSReports::is_something_in_this_matrix(
  x = table_raw, 
  search_for = "J"), 
  "There is a 'J' in this matrix!", 
  ""))

# Create pretty version of table that will go into report
table_print <- table_raw
table_print[,c("x", "y")] <- NMFSReports::mod_number(table_print[,c("x", "y")], 
                                                     divideby = 1, 
                                                     comma_seperator = TRUE, 
                                                     digits = 2)

# example of how to add footnotes from a column of footnotes
# here, we'll add footnotes from the "footnotes" column to the content in the first column, where necessary
table_print <- NMFSReports::add_table_footnotes(table = table_print, 
                                   from_col = "footnotes", # either use the name of the column or number
                                   to_col = 1, # or the number of that column in that table
                                   delim = ",,,") 
table_print$footnotes<-NULL # remove column from final table

# here, I'll add a specific footnote to a specific place in the table
table_print <- NMFSReports::add_table_footnotes(table = table_print, 
                                   footnote = "Example footnote in a table 4.", 
                                   to_row = 2, 
                                   to_col = 2)

# apply multiple footnotes to multiple (same number) spots
table_print <- NMFSReports::add_table_footnotes(table = table_print, 
                                   footnote = c("Example footnote in a table 5.", 
                                                "Example footnote in a table 6."), 
                                   to_row = 2:3,
                                   to_col = 2)


# Format table 
table_print <- table_print %>%
  NMFSReports::format_cells(rows = 0, # make column names
               cols = 1:ncol(table_print), # for all columns
               fonttype = "bold") #%>% # bold
  # knitr::kable(row.names = FALSE, booktabs = TRUE) #print table in text

# save yo' stuff and do a lot of behind the scenes work
# alt: this does the same thing as calling "child = " in the chunk header
res <- knitr::knit_child(
  text = knitr::knit_expand(
    file = system.file("rmd/_child_save_tab.Rmd", package = "NMFSReports")), 
  quiet = TRUE
)
# `r res `
Table 2. – Here is a table!
col x y
A -0.01 -0.13
B -0.944 ,5 1.26
C6 -0.907 0.66
D8 ,9 -0.88 -0.36
E 0.24 0.89
F -0.92 0.23
G -0.19 -0.48
H -1.49 0.68
I -0.10 -1.12
J 0.13 2.08

Here in table 2, we see that…

References

Arrhenius S. 1889. Über die reaktionsgeschwindigkeit bei der inversion von rohrzucker durch säuren. Zeitschrift für physikalische Chemie 4: 226–248.
Fry FEJ. 1957. The physiology of fishes. London: Academic Press.

  1. Wow, this project is so cool!↩︎

  2. Here’s another, free-written footnote!↩︎

  3. footnote about how cool the pythagorean theorem is.↩︎

  4. Example footnote in a table 4.↩︎

  5. Example footnote in a table 5.↩︎

  6. Example footnote in a table 1.↩︎

  7. Example footnote in a table 6.↩︎

  8. Example footnote in a table 2.↩︎

  9. Example footnote in a table 3.↩︎