#if(!'knitcitations'%in%library()$results) install.packages('knitcitations', repos = 'http://cran.rstudio.com')
#if(!'knitr'%in%library()$results) install.packages('knitr', repos = 'http://cran.rstudio.com')
#if(!'stringr'%in%library()$results) install.packages('stringr', repos = 'http://cran.rstudio.com')
#if(!'devtools'%in%library()$results) install.packages('devtools', repos = 'http://cran.rstudio.com')
knitcitations::cite_options(cite.style = "numeric", citation_format = 'pandoc')
knitr::knit_hooks$set(
jkf_par = function(before, options, envir) {
if (before) {
par(cex.lab = 1.05,
cex.axis = 1.05,
mgp = c(3.25,0.7, 0),
tcl = -0.3,
font.lab = 2,
font = 2,
font.axis = 2,
tck = 0.015,
family = "serif",
lwd = 2) }
})
knitr::knit_hooks$set(
source = function(x, options){
if (!is.null(options$verbatim) && options$verbatim){
opts = gsub(",\\s*verbatim\\s*=\\s*TRUE\\s*", "", options$params.src)
bef = sprintf('\n\n ```{r %s}\n', opts, "\n")
stringr::str_c(
bef,
knitr:::indent_block(paste(x, collapse = '\n'), " "),
"\n ```\n"
)
} else {
stringr::str_c("\n\n```", tolower(options$engine), "\n",
paste(x, collapse = '\n'), "\n```\n\n"
)
}
})
knitr::knit_hooks$set(
latex = function(before, options, envir) {
if (before) {
if(output=='pdf') '\\vspace{7px}'
}
})
knitr::opts_chunk$set(message = FALSE,
warning = FALSE,
echo = FALSE,
results = "asis",
jkf_par = TRUE,
fig.align = 'center',
fig.pos = 'h',
fig.width = 7,
fig.height = 5,
comment = NA)
getYAML <- function(file) {
lines <- readLines(file)
header <- list(lines[min(which(lines%in%'---'))+1:max(which(lines%in%'---'))-1])
header <- unlist(header)
header <- header[-c(1,length(header))]
output <- header[which(header%in%'output:')+1]
output <- gsub(" ", "", unlist(strsplit(output, ':'))[1])
output <- gsub('_document', '', output)
yaml <- list()
yaml$output <- output
invisible(yaml)
}
# getPackage <- function(pkg = NULL, repo = 'CRAN') {
#
# if(repo=='CRAN') {
#
# eval(substitute(ifelse(!a%in%library()$results,
# {install.packages(a, repos = 'http://cran.rstudio.com') ; library(a)},
# library(a)),
# list(a = pkg)))
#
# } else {
#
# eval(substitute(ifelse(!a%in%library()$results,
# {devtools::install_github(paste(c(b,a), collapse = '/')) ; library(a) },
# library(a)),
# list(a = pkg, b = repo)))
#
# }
# }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.