Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rmd code snippets #1

Open
RobertASmith opened this issue Feb 15, 2022 · 1 comment
Open

Rmd code snippets #1

RobertASmith opened this issue Feb 15, 2022 · 1 comment

Comments

@RobertASmith
Copy link
Owner

RobertASmith commented Feb 15, 2022

Text colour:

  • In YAML:
    • \usepackage{xcolor}
    • \definecolor{Mycolor2}{HTML}{00F9DE}
  • In text: \textcolor{red}{different colours} by name or \textcolor{Mycolor2}{hexcodes}.

Higher/Lower:

make_RMDpercdiff <- function(a, b, round_digits){

# calculate percent difference
pcnt_diff <- (a - b) / b * 100
pcnt_diff <- round(x = pcnt_diff, digits = round_digits)

# if higher than 0 then higher than, otherwise lower than
if(pcnt_diff>0){
    out <- paste0(abs(pcnt_diff), "% higher than")
            }else{
                out <- paste0(abs(pcnt_diff), "% lower than")
                    }
# if equal to zero then over-write with the same as
if(pcnt_diff == 0){
    out <- paste0("the same as")
       }

return(out)

}

make_RMD_higher_lower <- function(a, b){

# calculate percent difference
input_diff <- a - b

# if higher than 0 then higher than, otherwise lower than
if(input_diff>0){
    out <- paste0(abs(input_diff), " higher than")
            }else{
                out <- paste0(abs(input_diff), " lower than")
                    }
# if equal to zero then over-write with the same as
if(input_diff == 0){
    out <- paste0("the same as")
       }

return(out)

}

run tests:

testthat::expect_equal(object = make_RMD_higher_lower(5,5),
expected = "the same as")

for(i in runif(n = 100, min = 5.1,max = 1e+7)){
testthat::expect_equal(object = make_RMD_higher_lower(i,5),
expected = paste0(abs(i - 5)," higher than"))
}

for(i in runif(n = 100,min = -1e+8,max = 4.99)){
testthat::expect_equal(object = make_RMD_higher_lower(i,5),
expected = paste0(abs(i - 5)," lower than"))
}

References

  • at reference location:
  • in YAML: bibliography: report/example.bib
  • in example.bib:

@Article{smith2020making,
title={Making health economic models Shiny: A tutorial},
author={Smith, Robert and Schneider, Paul},
journal={Wellcome Open Research},
volume={5},
year={2020},
publisher={The Wellcome Trust}
}

Setting counter again for Appendices

\setcounter{figure}{0}
\renewcommand{\thefigure}{A\arabic{figure}}

\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}

1st page title Logo

title: |
{width=1in}
\textcolor{primary}{Example of an RMarkdown document for Company automated reporting}

@RobertASmith
Copy link
Owner Author

Example YAML


title: |
{width=6cm}
\textcolor{primary}{Example of an RMarkdown document for automated reporting}
author: \textcolor{secondary}{An Anonymous Advanced Analytics Associate}
date: "r format(Sys.time(), '%B %d, %Y')"
abstract: \doublespacing Abstract text inserted here
keywords: "example, r markdown"
output: pdf_document
bibliography: report/example.bib
header-includes:

  • \usepackage{setspace}
  • \usepackage{fancyhdr}
  • \usepackage{amsmath}
  • \usepackage{caption}
  • \usepackage{xcolor}
  • \definecolor{primary}{HTML}{007C91}
  • \definecolor{secondary}{HTML}{003B5C}
  • \pagestyle{fancy}
    % center of header
  • \fancyhead[R]{\includegraphics[height=3.2cm]{figures/logo.jpg}}
    % center of footer
  • \fancyfoot[C]{DO NOT CIRCULATE}
    % page number on the left of even pages and right of odd pages
  • \fancyfoot[R]{\thepage}
  • \setlength{\headheight}{4cm}

params:
start_date: NULL
fig_labels: NULL
numeric_x: NULL
numeric_y: NULL
rmd_foo_list: NULL


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant