content
stringlengths 0
14.9M
| filename
stringlengths 44
136
|
---|---|
#' Get xSub file
#'
#' This function downloads individual files from \code{www.x-sub.org}. Function produces a data.frame, for the user's choice of data source, country, spatial and temporal units, and (optionally) writes this data.frame to disk, in multiple formats.
#'
#' @param data_source Name of data source. See \code{info_xSub()} for full list.
#' @param sources_type Type of data sources ("individual" or "multiple"). Character string.
#' @param data_type Type of dataset ("event" or "panel"). Character string.
#' @param country_iso3 Country code (ISO3). See \code{info_xSub()} for full list.
#' @param country_name Country name. See \code{info_xSub()} for full list.
#' @param space_unit Geographic level of analysis. Character string. Can be one of \code{"adm0"} (country), \code{"adm1"} (province), \code{"adm2"} (district), \code{"priogrid"} (grid cell), \code{"clea"} (electoral constituency). See \code{info_xSub(details=TRUE)} for availability by country.
#' @param time_unit Temporal level of analysis. Character string. Can be one of \code{"year"}, \code{"month"}, \code{"week"}, \code{"day"}. See \code{info_xSub(details=TRUE)} for availability by country.
#' @param geo_window Geographic window (if source_type="multiple"). Could be either of "1 km" (default) or "5 km". Character string or vector.
#' @param time_window Time window (if source_type="multiple"). Could be either of "1 day" (default) or "2 day". Character string or vector.
#' @param dyad_type Time window (if source_type="multiple"). Could be either of "undirected" (default) or "directed". Character string or vector.
#' @param out_dir Path to directory where files will be saved.
#' @param write_file Logical. If \code{write_file=TRUE}, selected file will be written to disk, at location specified by \code{out_dir}.
#' @param write_format Output file format. Can be one of \code{"csv"} (comma-separated values, default), \code{"R"} (RData format, compatible with R statistical programming language), \code{"STATA"} (dta format, compatible with Stata 14).
#' @param verbose Logical. When \code{verbose=TRUE}, file download progress is printed to console.
#' @import haven RCurl countrycode
#' @importFrom utils data download.file read.csv unzip write.csv globalVariables
#' @export
#' @seealso \code{\link{info_xSub}}, \code{\link{get_xSub_multi}}
#' @examples
#' # Check which countries are available for ACLED
#' info_xSub(data_source="ACLED")
#'
#' # Download ACLED data for Egypt, at country-year level
#' \dontrun{
#' my_file <- get_xSub(data_source = "ACLED",country_iso3 = "EGY",
#' space_unit = "adm0",time_unit = "year")
#'}
#'
#' # Download ACLED data for Egypt, at district-month level
#' \dontrun{
#' my_file <- get_xSub(data_source = "ACLED",country_iso3 = "EGY",
#' space_unit = "adm2",time_unit = "month")
#' }
#'
#' # With country name instead of ISO3 code
#' \dontrun{
#' my_file <- get_xSub(data_source = "ACLED",country_name = "Egypt",
#' space_unit = "adm2",time_unit = "month")
#' }
#'
#' \dontrun{
#' # Download ACLED data for Egypt, event level
#' my_file <- get_xSub(data_source = "ACLED",country_iso3 = "EGY",
#' data_type = "event")
#'}
#'
#' \dontrun{
#' # Download multiple source data for Egypt, at province-month level
#' my_file <- get_xSub(sources_type = "multiple",country_iso3 = "EGY",
#' space_unit = "adm1",time_unit = "month", geo_window = "1 km",
#' time_window = "1 day", dyad_type = "undirected")
#'}
get_xSub <- function(data_source,sources_type="individual",data_type="spatial panel",
country_iso3=NULL,country_name=NULL,space_unit,time_unit,
geo_window="1 km",time_window="1 day",dyad_type="undirected",
out_dir=getwd(),write_file=TRUE,write_format="csv",verbose=FALSE){
# Units of analysis
space.agg <- c("adm0","adm1","adm2","priogrid","clea")
time.agg <- c("year","month","week","day")
space.ix <- c("ID_0","ID_1","ID_2","PRIO_GID","CLEA_CST")
time.ix <- c("YEAR","YRMO","WID","TID")
# Parent directory
url_dir <- "http://cross-sub.org/api/data/"
# Country name
if(length(country_iso3)==0&length(country_name)>0){
country_iso3 <- countrycode::countrycode(country_name,"country.name","iso3c")
}
# File name
if((grepl("^i|^I",sources_type)&grepl("^s|^S|^p|^P",data_type))){
file_name <- paste0("xSub_",data_source,"_",country_iso3,"_",space_unit,"_",time_unit,".csv")
file_name_ <- file_name
zip_name <- paste0("xSub_",data_source,"_",country_iso3,"_",space_unit,"_",time_unit,".zip")
file_url <- paste0(url_dir,zip_name)
}
if(!(grepl("^i|^I",sources_type)&grepl("^s|^S|^p|^P",data_type))){
if((grepl("^i|^I",sources_type)&grepl("^e|^E",data_type))){
file_name <- paste0("xSub_",data_source,"_Events_",country_iso3,".csv")
file_name_ <- paste0("xSub_",data_source,"_",country_iso3,"_event.csv")
zip_name <- paste0("xSub_",data_source,"_",country_iso3,"_event.zip")
file_url <- paste0(url_dir,zip_name)
}
if((grepl("^m|^M",sources_type)&grepl("^e|^E",data_type))){
if(length(geo_window)==0|length(time_window)==0|length(dyad_type)==0){stop('Please specify geo_window (\"1 km\" or \"5 km\"), time_window (\"1 day\" or \"2 day\") and dyad_type (\"undirected\" or \"directed\").')}
if(length(geo_window)>0&length(time_window)>0&length(dyad_type)>0){
gwz <- ifelse(grepl("^1",geo_window),"1km",ifelse(grepl("^5",geo_window),"5km",stop("geo_window can only be \"1 km\" or \"5 km\"")))
twz <- ifelse(grepl("^1",time_window),"1d",ifelse(grepl("^2",time_window),"2d",stop("time_window can only be \"1 day\" or \"2 day\"")))
dyz <- ifelse(grepl("^u|^U",dyad_type),"B",ifelse(grepl("^d|^D",dyad_type),"A",stop("dyad_type can only be \"undirected\" or \"directed\"")))
data_source <- paste0("MELTT",gwz,twz,dyz)
file_name <- paste0("xSub_MELTT",gwz,twz,dyz,"_Events_",country_iso3,".csv")
file_name_ <- paste0("xSub_MELTT",gwz,twz,dyz,"_",country_iso3,"_event.csv")
zip_name <- paste0("xSub_MELTT",gwz,twz,dyz,"_",country_iso3,"_event.zip")
file_url <- paste0(url_dir,zip_name)
}
}
if((grepl("^m|^M",sources_type)&grepl("^s|^S|^p|^P",data_type))){
if(length(geo_window)==0|length(time_window)==0|length(dyad_type)==0){stop('Please specify geo_window (\"1 km\" or \"5 km\"), time_window (\"1 day\" or \"2 day\") and dyad_type (\"undirected\" or \"directed\").')}
if(length(geo_window)>0&length(time_window)>0&length(dyad_type)>0){
gwz <- ifelse(grepl("^1",geo_window),"1km",ifelse(grepl("^5",geo_window),"5km",stop("geo_window can only be \"1 km\" or \"5 km\"")))
twz <- ifelse(grepl("^1",time_window),"1d",ifelse(grepl("^2",time_window),"2d",stop("time_window can only be \"1 day\" or \"2 day\"")))
dyz <- ifelse(grepl("^u|^U",dyad_type),"B",ifelse(grepl("^d|^D",dyad_type),"A",stop("dyad_type can only be \"undirected\" or \"directed\"")))
data_source <- paste0("MELTT",gwz,twz,dyz)
file_name <- paste0("xSub_MELTT",gwz,twz,dyz,"_",country_iso3,"_",space_unit,"_",time_unit,".csv")
file_name_ <- file_name
zip_name <- paste0("xSub_MELTT",gwz,twz,dyz,"_",country_iso3,"_",space_unit,"_",time_unit,".zip")
file_url <- paste0(url_dir,zip_name)
}
}
}
# Error handling
downloadFail <- FALSE
tryCatch({
# Download and unzip
if(Sys.info()['sysname']!="Windows"){
temp <- tempfile()
download.file(file_url,temp,cacheOK = TRUE,quiet = (!verbose))
xSub_file <- read.csv(unzip(temp, files=file_name))
unlink(temp)
if(file.exists(file_name)){file.remove(file_name)}
}
if(Sys.info()['sysname']=="Windows"){
temp <- tempfile()
# gsub("csv$","RData",file_name)
# download.file(file_url,destfile="TEMP.zip")
# unz("TEMP.zip")
download.file(file_url,temp,cacheOK = TRUE,quiet = (!verbose),mode="wb")
xSub_file <- read.csv(unzip(temp, files=file_name))
unlink(temp)
if(file.exists(file_name)){file.remove(file_name)}
}
}, warning = function(w) {
downloadFail <<- TRUE
}, error = function(e) {
message("Cannot access xSub server. Please check your internet connection and try again.")
downloadFail <<- TRUE
}, finally = {
})
if(downloadFail){
cat("Cannot access xSub server. Please check your internet connection and try again.")
return()
} else {
# Add source column
if(length(xSub_file$SOURCE)==0){
xSub_file$SOURCE <- data_source[1]
xSub_file <- xSub_file[,c(ncol(xSub_file),1:(ncol(xSub_file)-1))]
}
# Write file
if(write_file){
if(write_format=="csv"){
write.csv(xSub_file,file=paste0(out_dir,"/",file_name_),fileEncoding = "UTF-8",row.names = FALSE)
}
if(write_format%in%c("R","RData")){
save(xSub_file,file=paste0(out_dir,"/",gsub("csv$","RData",file_name_)))
}
if(write_format%in%c("STATA","stata","dta")){
haven::write_dta(data=xSub_file,path = paste0(out_dir,"/",gsub("csv$","dta",file_name_)),version = 14)
}
}
# Return object
return(xSub_file)
}
}
| /scratch/gouwar.j/cran-all/cranData/xSub/R/get_xSub.R |
#' Get xSub files for multiple countries
#'
#' This function downloads and merges mutiple country files from \code{www.x-sub.org}. Syntax is similar to \code{get_xSub()}.
#'
#' @param data_source Name of data source. Character string. See \code{info_xSub()} for full list.
#' @param sources_type Type of data sources ("individual" or "multiple"). Character string.
#' @param data_type Type of dataset ("event" or "panel"). Character string.
#' @param country_iso3 Country codes (ISO3). Character string or vector. See \code{info_xSub()} for full list. If left blank, function will download all available countries for selected data source.
#' @param space_unit Geographic level of analysis. Character string. Can be one of \code{"adm0"} (country), \code{"adm1"} (province), \code{"adm2"} (district), \code{"priogrid"} (grid cell), \code{"clea"} (electoral constituency). See \code{info_xSub(details=TRUE)} for availability by country.
#' @param time_unit Temporal level of analysis. Character string. Can be one of \code{"year"}, \code{"month"}, \code{"week"}, \code{"day"}. See \code{info_xSub(details=TRUE)} for availability by country.
#' @param geo_window Geographic window (if source_type="multiple"). Could be either of "1 km" or "5 km". Character string or vector.
#' @param time_window Time window (if source_type="multiple"). Could be either of "1 day" or "2 day". Character string or vector.
#' @param dyad_type Time window (if source_type="multiple"). Could be either of "undirected" or "directed". Character string or vector.
#' @param merge_files Logical. If \code{merge_files=TRUE} (default), function will combine individual country files into single data.frame, and write single file to disk. If \code{merge_files=FALSE}, function produces a list, and writes individual country files to disk separately.
#' @param out_dir Path to directory where files will be saved. Character string.
#' @param write_file Logical. If \code{write_file=TRUE}, selected file will be written to disk, at location specified by \code{out_dir}.
#' @param write_format Output file format. Character string. Can be one of \code{"csv"} (comma-separated values, default), \code{"R"} (RData format, compatible with R statistical programming language), \code{"STATA"} (dta format, compatible with Stata 14).
#' @param verbose Logical. When \code{verbose=TRUE}, file download progress is printed to console..
#' @export
#' @seealso \code{\link{info_xSub}}, \code{\link{get_xSub}}
#' @import haven RCurl countrycode
#' @importFrom utils data download.file read.csv unzip write.csv globalVariables
#' @export
#' @seealso \code{\link{info_xSub}}, \code{\link{get_xSub}}
#' @examples
#' # Check which countries are available for GED
#' info_xSub(data_source="GED")
#'
#' # Example with two countries
#' \dontrun{
#' my_file <- get_xSub_multi(data_source = "PITF",country_iso3 = c("ALB","ARM"),
#' space_unit = "adm0",time_unit = "year")
#' }
#'
#' # Example with two countries
#' \dontrun{
#' my_file <- get_xSub_multi(data_source = "GED",country_iso3 = c("EGY","AGO"),
#' space_unit = "adm1",time_unit = "month")
#' }
#'
#' # Example with two countries, multiple sources, event-level
#' \dontrun{
#' my_file <- get_xSub_multi(sources_type = "multiple",data_type="event",country_iso3 = c("EGY","AGO"))
#' }
#'
#' # Example with all countries (WARNING: this can take a long time to run)
#' \dontrun{
#' my_file <- get_xSub_multi(data_source = "BeissingerProtest",country_iso3 = NULL,
#' space_unit = "adm0",time_unit = "year")
#' }
get_xSub_multi <- function(data_source,sources_type="individual",data_type="spatial panel",
country_iso3=NULL,space_unit,time_unit,
geo_window="1 km",time_window="1 day",dyad_type="undirected",
merge_files=TRUE,out_dir=getwd(),write_file=FALSE,
write_format="csv",verbose=FALSE){
# # Load dependencies
# list.of.packages <- c("RCurl","countrycode"); new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]; if(length(new.packages)){install.packages(new.packages,dependencies=TRUE)}; lapply(list.of.packages, require, character.only = TRUE)
print("Assembling file list...")
# Check which files exist
url_dir <- "http://cross-sub.org/api/data/"
if(length(country_iso3)>0){cntz <- country_iso3}
if(length(country_iso3)==0){
cntz <- sort(unique(countrycode::codelist$iso3c))
}
if((grepl("^i|^I",sources_type)&grepl("^s|^S|^p|^P",data_type))){
file_urlz <- paste0(url_dir,"xSub_",data_source,"_",cntz,"_",space_unit,"_",time_unit,".zip")
}
if(!(grepl("^i|^I",sources_type)&grepl("^s|^S|^p|^P",data_type))){
if((grepl("^i|^I",sources_type)&grepl("^e|^E",data_type))){
file_urlz <- paste0(url_dir,"xSub_",data_source,"_",cntz,"_event.zip")
}
if((grepl("^m|^M",sources_type)&grepl("^e|^E",data_type))){
if(length(geo_window)==0|length(time_window)==0|length(dyad_type)==0){stop('Please specify geo_window (\"1 km\" or \"5 km\"), time_window (\"1 day\" or \"2 day\") and dyad_type (\"undirected\" or \"directed\").')}
if(length(geo_window)>0&length(time_window)>0&length(dyad_type)>0){
gwz <- ifelse(grepl("^1",geo_window),"1km",ifelse(grepl("^5",geo_window),"5km",stop("geo_window can only be \"1 km\" or \"5 km\"")))
twz <- ifelse(grepl("^1",time_window),"1d",ifelse(grepl("^2",time_window),"2d",stop("time_window can only be \"1 day\" or \"2 day\"")))
dyz <- ifelse(grepl("^u|^U",dyad_type),"B",ifelse(grepl("^d|^D",dyad_type),"A",stop("dyad_type can only be \"undirected\" or \"directed\"")))
data_source <- paste0("MELTT",gwz,twz,dyz)
file_urlz <- paste0(url_dir,"xSub_",data_source,"_",cntz,"_event.zip")
}
}
if((grepl("^m|^M",sources_type)&grepl("^s|^S|^p|^P",data_type))){
if(length(geo_window)==0|length(time_window)==0|length(dyad_type)==0){stop('Please specify geo_window (\"1 km\" or \"5 km\"), time_window (\"1 day\" or \"2 day\") and dyad_type (\"undirected\" or \"directed\").')}
if(length(geo_window)>0&length(time_window)>0&length(dyad_type)>0){
gwz <- ifelse(grepl("^1",geo_window),"1km",ifelse(grepl("^5",geo_window),"5km",stop("geo_window can only be \"1 km\" or \"5 km\"")))
twz <- ifelse(grepl("^1",time_window),"1d",ifelse(grepl("^2",time_window),"2d",stop("time_window can only be \"1 day\" or \"2 day\"")))
dyz <- ifelse(grepl("^u|^U",dyad_type),"B",ifelse(grepl("^d|^D",dyad_type),"A",stop("dyad_type can only be \"undirected\" or \"directed\"")))
data_source <- paste0("MELTT",gwz,twz,dyz)
file_urlz <- paste0(url_dir,"xSub_",data_source,"_",cntz,"_",space_unit,"_",time_unit,".zip")
}
}
}
exist_urlz <- c()
for (n in seq_along(file_urlz)){
e <- NULL
w <- NULL
z <- ""
tryCatch({
z <- RCurl::getBinaryURL(file_urlz[n], failonerror = TRUE)
}, warning = function(w) {
if(grepl("Could not resolve host",w)){message("Cannot access xSub server. Please check your internet connection and try again.")}
if(grepl("404 Not Found",w)){message(paste0("Country ",n," (",cntz[n],") unavailable from source ",data_source,". Looking for the rest..."))}
if(!grepl("404 Not Found",w)&!grepl("Could not resolve host",w)){message(paste0("Country ",n," (",cntz[n],"): ",w))}
z <<- ""
}, error = function(e) {
if(grepl("Could not resolve host",e)){message("Cannot access xSub server. Please check your internet connection and try again.")}
if(grepl("404 Not Found",e)){message(paste0("Country ",n," (",cntz[n],") unavailable from source ",data_source,". Looking for the rest..."))}
if(!grepl("404 Not Found",e)&!grepl("Could not resolve host",e)){message(paste0("Country ",n," (",cntz[n],"): ",e))}
z <<- ""
}, finally = {
})
if(length(z) > 1){exist_urlz[n] <- TRUE}
else{exist_urlz[n] <- FALSE}
}
country_iso3 <- cntz[exist_urlz]
if(length(country_iso3)>0){
# Loop
print("Downloading files...")
xSub_list <- lapply(seq_along(country_iso3),function(j){
get_xSub(data_source = data_source,data_type = data_type,country_iso3 = country_iso3[j],space_unit = space_unit,time_unit = time_unit,out_dir = out_dir,write_file = (!merge_files),write_format = write_format,verbose = verbose)
})
# Merge
if(merge_files){
print("Merging files...")
xSub_file <- do.call(rbind,xSub_list)
# Write file
if(write_file){
print("Writing to disk...")
if(grepl("^s|^S|^p|^P",data_type)){
file_name2 <- paste0("xSub_",data_source,"_",space_unit,"_",time_unit,".csv")
}
if(grepl("^e|^E",data_type)){
file_name2 <- paste0("xSub_",data_source,"_event.csv")
}
if(write_format=="csv"){
write.csv(xSub_file,file=paste0(out_dir,"/",file_name2),fileEncoding = "UTF-8",row.names = FALSE)
}
if(write_format%in%c("R","RData")){
save(xSub_file,file=paste0(out_dir,"/",gsub("csv$","RData",file_name2)))
}
if(write_format%in%c("STATA","stata","dta")){
# Load (or install) dependencies
# list.of.packages <- c("haven"); new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]; if(length(new.packages)){install.packages(new.packages,dependencies=TRUE)}; lapply(list.of.packages, require, character.only = TRUE)
write_dta(data=xSub_file,path = paste0(out_dir,"/",gsub("csv$","dta",file_name2)),version = 14)
}
}
# Return object
return(xSub_file)
}
else(
return(xSub_list)
)
}
else {return()}
}
| /scratch/gouwar.j/cran-all/cranData/xSub/R/get_xSub_multi.R |
#' Information on available xSub files
#'
#' This function reports the availability of files on the \code{www.x-sub.org} server, and corresponding country codes and units of analysis. For additional info, see \code{www.x-sub.org/about/what-is-xsub}.
#'
#' @param details Logical. If \code{details=TRUE}, function returns information on available units of analysis for each country.
#' @param data_source Subset results by data sources. Character string or vector.
#' @param sources_type Type of data sources ("individual" or "multiple"). Character string.
#' @param data_type Type of dataset ("event" or "panel"). Character string.
#' @param country_iso3 Subset results by country codes (ISO3). Character string or vector.
#' @param country_name Subset results by country name. Character string or vector.
#' @param geo_window Geographic window (if source_type="multiple"). Could be either of "1 km" or "5 km". Character string or vector.
#' @param time_window Time window (if source_type="multiple"). Could be either of "1 day" or "2 day". Character string or vector.
#' @param dyad_type Time window (if source_type="multiple"). Could be either of "undirected" or "directed". Character string or vector.
#' @import haven RCurl countrycode
#' @importFrom utils data download.file read.csv unzip write.csv globalVariables
#' @export
#' @seealso \code{\link{get_xSub}}, \code{\link{get_xSub_multi}}
#' @examples
#' # General info on data sources and countries
#' info_xSub()
#'
#' # Available files for Pakistan
#' info_xSub(country_name = "Pakistan")
#'
#' # Detailed info for Pakistan
#' info_xSub(details=TRUE,country_name = "Pakistan")
#'
#' # Available files for SCAD data source
#' info_xSub(data_source = "SCAD")
#'
#' # Available files for SCAD data source, event-level
#' info_xSub(data_source = "SCAD", data_type = "event")
#'
#' # Multiple data sources, directed dyads
#' info_xSub(sources_type = "multiple", dyad_type = "directed")
#'
#' # Multiple data sources, directed dyads, Russia
#' info_xSub(sources_type = "multiple", dyad_type = "directed", country_name = "Russia")
info_xSub <- function(details=FALSE,sources_type="individual",data_type="panel",
data_source=NULL,country_iso3=NULL,country_name=NULL,
geo_window=NULL,time_window=NULL,dyad_type=NULL){
# # Suppres notes
# suppressBindingNotes <- function(variablesMentionedInNotes) {
# for(variable in variablesMentionedInNotes) {
# assign(variable,NULL, envir = .GlobalEnv)
# }
# }
# suppressBindingNotes(c("countrycode_data","census_individual_raw","census_individual_spatial","census_multiple_raw","census_multiple_spatial"))
# utils::suppressForeignCheck(c("countrycode_data","census_individual_raw","census_individual_spatial","census_multiple_raw","census_multiple_spatial"))
# utils::globalVariables(c("countrycode_data","census_individual_raw","census_individual_spatial","census_multiple_raw","census_multiple_spatial"),add=FALSE)
if(grepl("^I|^i",sources_type)&grepl("^s|^p|^S|^P",data_type)){xSub_census <- xSub_census_individual_spatial}
if(grepl("^I|^i",sources_type)&grepl("^E|^e",data_type)){xSub_census <- xSub_census_individual_raw}
if(grepl("^M|^m",sources_type)&grepl("^s|^p|^S|^P",data_type)){xSub_census <- xSub_census_multiple_spatial}
if(grepl("^M|^m",sources_type)&grepl("^E|^e",data_type)){xSub_census <- xSub_census_multiple_raw}
if(length(data_source)==0&length(country_iso3)==0&length(country_name)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0){
print(paste0(rep("%%%%",10),collapse=""));print(paste0(rep("%%%%",10),collapse=""))
print("xSub datasets / by source")
print(paste0(rep("%%%%",10),collapse=""));print(paste0(rep("%%%%",10),collapse=""))
print(xSub_census$level0_bysource)
print(paste0(rep("%%%%",10),collapse=""));print(paste0(rep("%%%%",10),collapse=""))
print("xSub datasets / by country")
print(paste0(rep("%%%%",10),collapse=""));print(paste0(rep("%%%%",10),collapse=""))
print(xSub_census$level0_bycountry)
print("For more info, select details=TRUE, and subset by data source or country")
}
if(grepl("^I|^i",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1)
print("For more info, subset by data source or country")
}
if(grepl("^I|^i",sources_type)&details==FALSE&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level1[xSub_census$level1$country_iso3%in%country_iso3,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^I|^i",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^I|^i",sources_type)&details==FALSE&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level1[grep(paste0(country_name,collapse="|"),xSub_census$level1$country_name),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^I|^i",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grep(paste0(country_name,collapse="|"),xSub_census$level2$country_name),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^I|^i",sources_type)&details==FALSE&length(data_source)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1[xSub_census$level1$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^I|^i",sources_type)&details==TRUE&length(data_source)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^I|^i",sources_type)&length(data_source)>0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^I|^i",sources_type)&length(data_source)>0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^I|^i",sources_type)&length(data_source)>0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(country_iso3)==0&length(country_name)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0){
print(xSub_census$level1)
print("For more info, subset by country, dyad type, geographic or time window")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)==0&length(country_iso3)>0&length(country_name)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0){
print(xSub_census$level1[xSub_census$level1$country_iso3%in%country_iso3,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(country_iso3)>0&length(country_name)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)==0&length(country_iso3)==0&length(country_name)>0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0){
print(xSub_census$level1[grep(paste0(country_name,collapse="|"),xSub_census$level1$country_name),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(country_iso3)==0&length(country_name)>0&length(geo_window)==0&length(time_window)==0&length(dyad_type)==0){
print(xSub_census$level2[grep(paste0(country_name,collapse="|"),xSub_census$level2$country_name),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1[xSub_census$level1$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&length(data_source)>0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)>0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)>0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1[grepl(geo_window,xSub_census$level1$geo_window),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level2[grepl(geo_window,xSub_census$level2$geo_window),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1[grepl(time_window,xSub_census$level1$time_window),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level2[grepl(time_window,xSub_census$level2$time_window),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1[grepl(paste0("^",dyad_type),xSub_census$level1$dyad_type),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level2[grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1[grepl(geo_window,xSub_census$level1$geo_window)&grepl(time_window,xSub_census$level1$time_window),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level2[grepl(geo_window,xSub_census$level2$geo_window)&grepl(time_window,xSub_census$level2$time_window),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1[grepl(time_window,xSub_census$level1$time_window)&grepl(paste0("^",dyad_type),xSub_census$level1$dyad_type),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level2[grepl(time_window,xSub_census$level2$time_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1[grepl(geo_window,xSub_census$level1$geo_window)&grepl(paste0("^",dyad_type),xSub_census$level1$dyad_type),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level2[grepl(geo_window,xSub_census$level2$geo_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==FALSE&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level1[grepl(geo_window,xSub_census$level1$geo_window)&grepl(time_window,xSub_census$level1$time_window)&grepl(paste0("^",dyad_type),xSub_census$level1$dyad_type),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&details==TRUE&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)==0){
print(xSub_census$level2[grepl(geo_window,xSub_census$level2$geo_window)&grepl(time_window,xSub_census$level2$time_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
print("For more info, subset by country")
}
if(grepl("^M|^m",sources_type)&length(data_source)>0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(geo_window,xSub_census$level2$geo_window),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(time_window,xSub_census$level2$time_window),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(geo_window,xSub_census$level2$geo_window)&grepl(time_window,xSub_census$level2$time_window),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(time_window,xSub_census$level2$time_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(geo_window,xSub_census$level2$geo_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)>0&length(country_name)==0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(geo_window,xSub_census$level2$geo_window)&grepl(time_window,xSub_census$level2$time_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)>0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&grepl(geo_window,xSub_census$level2$geo_window),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&grepl(time_window,xSub_census$level2$time_window),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&grepl(geo_window,xSub_census$level2$geo_window)&grepl(time_window,xSub_census$level2$time_window),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&grepl(time_window,xSub_census$level2$time_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&grepl(geo_window,xSub_census$level2$geo_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)==0&length(country_name)>0){
print(xSub_census$level2[grepl(paste0(country_name,collapse="|"),xSub_census$level2$country_name)&grepl(geo_window,xSub_census$level2$geo_window)&grepl(time_window,xSub_census$level2$time_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)>0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&xSub_census$level2$data_source%in%data_source,])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)==0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(geo_window,xSub_census$level2$geo_window),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(time_window,xSub_census$level2$time_window),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)==0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)==0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(geo_window,xSub_census$level2$geo_window)&grepl(time_window,xSub_census$level2$time_window),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)==0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(time_window,xSub_census$level2$time_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)==0&length(dyad_type)>0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(geo_window,xSub_census$level2$geo_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
if(grepl("^M|^m",sources_type)&length(data_source)==0&length(geo_window)>0&length(time_window)>0&length(dyad_type)>0&length(country_iso3)>0&length(country_name)>0){
print(xSub_census$level2[xSub_census$level2$country_iso3%in%country_iso3&grepl(geo_window,xSub_census$level2$geo_window)&grepl(time_window,xSub_census$level2$time_window)&grepl(paste0("^",dyad_type),xSub_census$level2$dyad_type),])
print("* daily-level data available only for adm0, adm1")
}
}
| /scratch/gouwar.j/cran-all/cranData/xSub/R/info_xSub.R |
#' Census of individual-source event-level datasets in xSub (updated June 15, 2020)
#'
#' A list of data sources and countries available for download. Used by \code{info_xSub()}
#'
#' @format A list with 4 elements:
#' \describe{
#' \item{level0_bysource}{Countries organized by \code{data_source}. List object, where each sub-entry is also a list, containing entries for \code{data_source},\code{country_iso3},\code{country_name}.}
#' \item{level0_bycountry}{Data sources organized by country. List of data.frames, where each row is a country, with columns for \code{country_iso3},\code{country_name},\code{data_sources}.}
#' \item{level1}{Detailed information on data sources, countries and spatial levels of analysis. data.frame, where each row is a source-country combination, with columns for \code{data_source},\code{country_iso3},\code{country_name},\code{units}.}
#' \item{all_countries}{Vector of all country ISO3 codes. Used by \code{get_xSub_multi}.}
#' }
#' @source \url{http://www.x-sub.org/}
"xSub_census_individual_raw"
| /scratch/gouwar.j/cran-all/cranData/xSub/R/xSub_census_individual_raw.R |
#' Census of individual-source panel datasets in xSub (updated June 15, 2020)
#'
#' A list of data sources, countries and levels of analysis available for download. Used by \code{info_xSub()}
#'
#' @format A list with 6 elements:
#' \describe{
#' \item{level0_bysource}{Countries organized by \code{data_source}. List object, where each sub-entry is also a list, containing entries for \code{data_source},\code{country_iso3},\code{country_name}.}
#' \item{level0_bycountry}{Data sources organized by country. List of data.frames, where each row is a country, with columns for \code{country_iso3},\code{country_name},\code{data_sources}.}
#' \item{level1}{Detailed information on data sources, countries and spatial levels of analysis. data.frame, where each row is a source-country combination, with columns for \code{data_source},\code{country_iso3},\code{country_name},\code{space_units},\code{time_units}.}
#' \item{level2}{Detailed information on data sources, countries, spatial and temporal levels of analysis. data.frame, where each row is a source-country-spatial unit combination, with columns for \code{data_source},\code{country_iso3},\code{country_name},\code{space_unit},\code{time_units}.}
#' \item{level3}{File census. data.frame, where each row is a single file, with columns for \code{file_name},\code{data_source},\code{country_iso3},\code{country_name},\code{space_unit},\code{time_unit}.}
#' \item{all_countries}{Vector of all country ISO3 codes. Used by \code{get_xSub_multi}.}
#' }
#' @source \url{http://www.x-sub.org/}
"xSub_census_individual_spatial"
| /scratch/gouwar.j/cran-all/cranData/xSub/R/xSub_census_individual_spatial.R |
#' Census of multiple-source event-level datasets in xSub (updated June 15, 2020)
#'
#' A list of data sources, countries and levels of analysis available for download. Used by \code{info_xSub()}
#'
#' @format A list with 4 elements:
#' \describe{
#' \item{level0_bysource}{Countries organized by \code{data_source}. List object, where each sub-entry is also a list, containing entries for \code{data_source},\code{geo_window},\code{time_window},\code{dyad_type},\code{country_iso3},\code{country_name}.}
#' \item{level0_bycountry}{Data sources organized by country. List of data.frames, where each row is a country, with columns for \code{country_iso3},\code{country_name},\code{geo_window},\code{time_window},\code{dyad_type},\code{data_sources}.}
#' \item{level1}{Detailed information on data sources, countries and spatial levels of analysis. data.frame, where each row is a source-country combination, with columns for \code{data_source},\code{geo_window},\code{time_window},\code{dyad_type},\code{country_iso3},\code{country_name},\code{units}.}
#' \item{all_countries}{Vector of all country ISO3 codes. Used by \code{get_xSub_multi}.}
#' }
#' @source \url{http://www.x-sub.org/}
"xSub_census_multiple_raw"
| /scratch/gouwar.j/cran-all/cranData/xSub/R/xSub_census_multiple_raw.R |
#' Census of multiple-source panel datasets in xSub (updated June 15, 2020)
#'
#' A list of data sources, countries and levels of analysis available for download. Used by \code{info_xSub()}
#'
#' @format A list with 6 elements:
#' \describe{
#' \item{level0_bysource}{Countries organized by \code{data_source}. List object, where each sub-entry is also a list, containing entries for \code{data_source},\code{geo_window},\code{time_window},\code{dyad_type},\code{country_iso3},\code{country_name}.}
#' \item{level0_bycountry}{Data sources organized by country. List of data.frames, where each row is a country, with columns for \code{country_iso3},\code{country_name},\code{geo_window},\code{time_window},\code{dyad_type},\code{data_sources}.}
#' \item{level1}{Detailed information on data sources, countries and spatial levels of analysis. data.frame, where each row is a source-country combination, with columns for \code{data_source},\code{geo_window},\code{time_window},\code{dyad_type},\code{country_iso3},\code{country_name},\code{space_units},\code{time_units}.}
#' \item{level2}{Detailed information on data sources, countries, spatial and temporal levels of analysis. data.frame, where each row is a source-country-spatial unit combination, with columns for \code{data_source},\code{geo_window},\code{time_window},\code{dyad_type},\code{country_iso3},\code{country_name},\code{space_unit},\code{time_units}.}
#' \item{level3}{File census. data.frame, where each row is a single file, with columns for \code{file_name},\code{data_source},\code{geo_window},\code{time_window},\code{dyad_type},\code{country_iso3},\code{country_name},\code{space_unit},\code{time_unit}.}
#' \item{all_countries}{Vector of all country ISO3 codes. Used by \code{get_xSub_multi}.}
#' }
#' @source \url{http://www.x-sub.org/}
"xSub_census_multiple_spatial"
| /scratch/gouwar.j/cran-all/cranData/xSub/R/xSub_census_multiple_spatial.R |
#' Calculates the Net/Gross ratio used under the CEM regulatory framework
#' @title Calculates the Net/Gross ratio (NGR)
#' @param MtM_Vector A vector containing the trades to be netted
#' @return The Net-Gross ratio (NGR)
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#'
CalcNGR = function(MtM_Vector)
{
if (all(MtM_Vector== 0))
{ NGR = 1
} else if(all(MtM_Vector< 0))
{ NGR = 0
} else
{ NGR = max(sum(MtM_Vector),0)/sum(max(MtM_Vector,0))
}
return(NGR)
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/CalcNGR.R |
#' Calculates the probablity of the default on specific time points by using the spread of the corresponding credit curve and the loss given default
#' @title Calculates the Probablity of Default
#' @param spread The spread based on the credit curve
#' @param LGD The loss-given-default
#' @param time_points The timepoints that the analysis is performed on
#' @return A vector containing the probablity of default on the specified timepoints
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#'
CalcPD = function(spread, LGD, time_points)
{
num_of_points = length(time_points)
spread = spread/10^4
PD = exp(-(spread[1:(num_of_points-1)]*time_points[1:(num_of_points-1)])/LGD) - exp(-(spread[2:num_of_points]*time_points[2:num_of_points])/LGD)
PD[PD<0] = 0
return(PD)
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/CalcPD.R |
#' Calculates the simulated exposure profile (EE, NEE, PFE, EEE) by use of the Hull-White model. Two sets of results are provided:
#' one after taking into account the marging agreement and one assuming that there is no marging agreement present
#' @title Calculated the Simulated Exposure Profile
#' @param discount_factors The discount curve derived from the spot curve
#' @param spot_curve The curve derived from interpolating the market spot rates
#' @param CSA The margin agreement
#' @param trades The list of the trade objects
#' @param time_points The timepoints that the analysis is performed on
#' @param sim_data A list containing simulation-related data (model parameters and number of simulation)
#' @param framework regulatory framework can be 'IMM','SACCR','CEM'
#' @return A list containing the exposure profile (both collateralized and uncollateralized)
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#'
CalcSimulatedExposure = function(discount_factors, time_points, spot_curve, CSA, trades, sim_data, framework)
{
num_of_points = length(time_points)
num_of_trades = length(trades)
Swap_MtMs = matrix(0,nrow=sim_data$num_of_sims, ncol = num_of_points)
Swap_MtMs_coll = matrix(0,nrow=sim_data$num_of_sims, ncol = num_of_points)
timesteps_diff = diff(time_points)
spot_interest_rate = spot_curve[1]
forward_curve = (discount_factors[1:(num_of_points-1)]/discount_factors[2:num_of_points]-1)/timesteps_diff
forward_curve = c(spot_interest_rate,forward_curve)
forward_diff=diff(forward_curve)
theta=forward_diff+sim_data$mean_reversion_a*forward_curve[2:length(forward_curve)]
set.seed(30269)
interest_rates = rep(0,length(num_of_points))
interest_rates[1] = spot_interest_rate
random_numbers = matrix(runif(sim_data$num_of_sims*(num_of_points-1)),nrow=sim_data$num_of_sims,ncol=num_of_points-1)
for(index in 1:num_of_trades)
{
maturity = trades[[index]]$Ei
swap_rate = trades[[index]]$pay_leg_rate
BuySell = ifelse(trades[[index]]$BuySell=='Buy',1,-1)
time_points_temp = time_points[time_points<=maturity]
num_of_points_temp = length(time_points_temp)
A = rep(0,length(time_points_temp))
B = (1-exp(-sim_data$mean_reversion_a*(maturity-time_points_temp)))/sim_data$mean_reversion_a
disc_factors = matrix(0,nrow=num_of_points_temp,ncol=num_of_points_temp)
dt = maturity/num_of_points_temp
for(j in 1:sim_data$num_of_sims)
{
Floating_leg = rep(0,num_of_points_temp)
for(i in 2:num_of_points_temp)
interest_rates[i] = interest_rates[i-1] + (theta[i-1]-sim_data$mean_reversion_a*interest_rates[i-1])*timesteps_diff[i-1]+ sim_data$volatility*qnorm(random_numbers[j,i-1])*sqrt(timesteps_diff[i-1])
for (i in 1:num_of_points_temp)
A[i] = discount_factors[num_of_points_temp]/discount_factors[i]*exp(B[i]*forward_curve[i]-(sim_data$volatility^2/(4*sim_data$mean_reversion_a))*(1-exp(-2*sim_data$mean_reversion_a*time_points_temp[i]))*B[i]^2)
for (i in 1:num_of_points_temp)
disc_factors[i,1:(num_of_points_temp-i+1)] = A[num_of_points_temp-i+1]*exp(-B[num_of_points_temp-i+1]*interest_rates[1:(num_of_points_temp-i+1)])
for (i in 0:(num_of_points_temp-1))
Floating_leg[i+1] = 1-disc_factors[num_of_points_temp-i,i+1]
Fixed_leg = dt*swap_rate*colSums(disc_factors,na.rm = TRUE)
Swap_MtM = (Floating_leg - Fixed_leg)*BuySell
Swap_MtMs[j,1:num_of_points_temp] = Swap_MtMs[j,1:num_of_points_temp] + Swap_MtM
Swap_MtMs_coll[j,1:num_of_points_temp] = Swap_MtMs_coll[j,1:num_of_points_temp] + CSA$ApplyThres(Swap_MtM)
}
if(framework=='IMM') trades[[index]]$MtM = Swap_MtMs[1,1]
}
exposure_profile = list()
exposure_profile$EE_uncoll = apply(apply(Swap_MtMs,c(1,2),function(x) ifelse(x>=0,x,NA)),2,mean,na.rm=TRUE)
exposure_profile$NEE_uncoll = apply(apply(Swap_MtMs,c(1,2),function(x) ifelse(x<0,x,NA)),2,mean,na.rm=TRUE)
exposure_profile$EE_uncoll[is.na(exposure_profile$EE_uncoll)] = 0
exposure_profile$NEE_uncoll[is.na(exposure_profile$NEE_uncoll)] = 0
exposure_profile$PFE_uncoll = apply(apply(Swap_MtMs,c(1,2),function(x) ifelse(x>0,x,NA)),2,quantile,sim_data$PFE_Percentile,na.rm=TRUE)
exposure_profile$PFE_uncoll[is.na(exposure_profile$PFE_uncoll)] = 0
exposure_profile$EE = apply(apply(Swap_MtMs_coll,c(1,2),function(x) ifelse(x>=0,x,NA)),2,mean,na.rm=TRUE)
exposure_profile$EE[is.na(exposure_profile$EE)] = 0
exposure_profile$NEE = apply(apply(Swap_MtMs_coll,c(1,2),function(x) ifelse(x<0,x,NA)),2,mean,na.rm=TRUE)
exposure_profile$NEE[is.na(exposure_profile$NEE)] = 0
exposure_profile$PFE = apply(apply(Swap_MtMs_coll,c(1,2),function(x) ifelse(x>0,x,NA)),2,quantile,sim_data$PFE_Percentile,na.rm=TRUE)
exposure_profile$PFE[is.na(exposure_profile$PFE)] = 0
EEE = rep(0,num_of_points)
EEE[1] = exposure_profile$EE[1]
for(i in 2:(num_of_points))
EEE[i] = max(EEE[i-1],exposure_profile$EE[i])
exposure_profile$EEE = EEE
return(exposure_profile)
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/CalcSimulatedExposure.R |
#' Calculates the Valuation Adjustment based on the exposure, the probability-of-default and the loss-given-default
#' @title Calculates the Valuation Adjustment
#' @param exposure A vector containing the exposure values on which the credit risk adjustment will be calculated
#' @param discount_factors The Discount Curve
#' @param PD The probability-of-Default
#' @param LGD The Loss-Given-Default
#' @return The Valuation Adjustment Value
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#'
CalcVA = function(exposure, discount_factors, PD, LGD)
{
VA = 0
num_of_points = length(discount_factors)
if(missing(LGD))
LGD = 1
for (i in 1:(num_of_points-1))
VA = VA + exposure[i]*discount_factors[i]*PD[i]
VA = -VA*LGD
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/CalcVA.R |
GenerateTimeGrid = function(CSA, maturity)
{
remargin_freq_annum = CSA$remargin_freq/360
mpor_days_annum = CSA$mpor_days/360
time_points = seq(0,maturity,remargin_freq_annum)
time_points_lookback = seq(remargin_freq_annum-mpor_days_annum,maturity-mpor_days_annum,remargin_freq_annum)
time_points = sort(c(time_points_lookback,time_points))
return(time_points)
} | /scratch/gouwar.j/cran-all/cranData/xVA/R/GenerateTimeGrid.R |
#' @description Checks if the specified currency is eligible to receive reduced regulatory risk weights
#'
#' @title Checks if specified currency is low risk
#' @param ccy The currency to be checked
#' @return TRUE if the currency is is eligible to receive reduced regulatory risk weights
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#' @references https://www.bis.org/basel_framework/chapter/MAR/50.htm?inforce=20230101&published=20200708
#'
#' @examples
#'
#' TRUE == IS_ELIGIBLE_CCY('EUR')
#'
IS_ELIGIBLE_CCY <- function(ccy) {
eligible_ccies = c('USD','EUR','GBP','AUD','CAD','SEK','JPY','REPORTING')
return(ccy %in% eligible_ccies)
} | /scratch/gouwar.j/cran-all/cranData/xVA/R/IS_ELIGIBLE_CCY.R |
#' @description Checks if the credit rating is investment grade or not (if not rating not recognised will be unrated)
#'
#' @title Checks if Credit rating is Investment Grade
#' @param credit_rating The Credit Rating to be checked
#' @return TRUE if Rating is Investment Grade
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#' @references https://en.wikipedia.org/wiki/Credit_rating
#'
#' @examples
#'
#' TRUE == IS_IG('AAA')
#'
IS_IG <- function(credit_rating) {
base_ratings = c('AA','A','BBB')
base_ratings = c('AAA', base_ratings, paste0(base_ratings,'+'), paste0(base_ratings,'-'))
return(credit_rating %in% base_ratings)
} | /scratch/gouwar.j/cran-all/cranData/xVA/R/IS_IG.R |
#' @description Loads the supervisory data (factors, correlation and option volatility)
#' for each Asset Class and SubClass
#' @title Supervisory Data Loading
#'
#' @return A list with the required data
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#' @references MAR50 - Credit Value Adjustment Framework
#' https://www.bis.org/basel_framework/chapter/MAR/50.htm?inforce=20230101&published=20200708
LoadSupervisoryCVAData <- function() {
file_names = c('IR_cormat_other_ccies','IR_cormat_eligible_ccies','CS_cormat_by_sector','CS_cormat_by_tenor','hedge_cpty_corr','superv_risk_weights','CS_ref_Sector_cormat',
'CS_Sector_cpty_cormat','COMM_RW','EQ_RW','IR_RW')
file_names_csv = paste0(file_names,'.csv')
superv = list()
for(i in 1:length(file_names))
{
superv[[i]] = read.csv(system.file("extdata", file_names_csv[i], package = "xVA"),header = TRUE,stringsAsFactors = FALSE,check.names = FALSE)
if(ncol(superv[[i]])==2)
{ superv[[i]][,2] = as.numeric(sub("%","",superv[[i]][,2]))/100
}else
{
if(file_names[i] %in% c('COMM_RW','EQ_RW'))
{ superv[[i]][,ncol( superv[[i]])] = as.numeric(sub("%","",superv[[i]][,ncol( superv[[i]])]))/100
}else
{ superv[[i]][,2:ncol( superv[[i]])] = apply( superv[[i]][,2:ncol( superv[[i]])],2, function(x) as.numeric(sub("%","",x))/100) }
}
}
names(superv) = file_names
return(superv)
} | /scratch/gouwar.j/cran-all/cranData/xVA/R/LoadSupervisoryCVAData.R |
utils::globalVariables("V1")
#' Calculates the CVA capital charge based on the standardized approach
#' @title Calculates the CVA Capital Charge
#' @param trades The full list of the Trade Objects
#' @param EAD Exposure-at-Default
#' @param reg_data A list containing data related to the regulatory calculations
#' @param superv A list containing supervisory data including correlations, risk weights etc
#' @param effective_maturity The effective maturity of the trades of the netting set
#' @param cva_sensitivities The effective maturity of the trades of the netting set
#' @return The CVA capital charge of the trade set
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
calcCVACapital = function(trades, EAD, reg_data, superv, effective_maturity, cva_sensitivities)
{
rating_table = HashTable('RatingsMapping.csv',"character","numeric")
reg_weight =rating_table$FindValue(reg_data$cpty_rating)
superv_rw = superv$superv_risk_weights[superv$superv_risk_weights$Sector == reg_data$cpty_sector, ifelse(IS_IG(reg_data$cpty_rating),2,3)]
if(reg_data$cva_framework=="STD-CVA")
{
df =(1-exp(-0.05*effective_maturity))/(effective_maturity*0.05)
cva_capital_charge = qnorm(0.99)*sqrt(sum(0.5*reg_weight*EAD*df*effective_maturity)^2+0.75*sum((reg_weight*EAD*df*effective_maturity)^2))
}else if(reg_data$cva_framework=="BA-CVA")
{
cva_capital_charge = EAD/1.4*superv_rw*effective_maturity
}else if(reg_data$cva_framework=="SA-CVA")
{
# The (oversimplifying) assumption being taken here that all trades belong to the same currency
ccy = unlist(unique(lapply(trades, function(x) x$Currency)))
if(IS_ELIGIBLE_CCY(ccy))
{
cormat = superv$IR_cormat_eligible_ccies
IR_RW = superv$IR_RW[1:nrow(superv$IR_RW)-1,2]
}else{
cormat = superv$IR_cormat_other_ccies
IR_RW = superv$IR_RW[1:nrow(superv$IR_RW)-1,3]
}
# IR part
superv_tenors = as.numeric(cormat[1:nrow(cormat)-1,1])
matching_indices = findInterval(cva_sensitivities$IR_tenors, superv_tenors)
mapped_IR_sens = data.table(cbind(cva_sensitivities$IR_delta, matching_indices))
mapped_IR_sens_summed = mapped_IR_sens[,sum(V1), by=matching_indices]
superv_tenors_indexed = data.table(superv_tenors = superv_tenors,matching_indices = seq(1,length(superv_tenors)))
mapped_IR_sens_summed = setkey(mapped_IR_sens_summed,"matching_indices")[setkey(superv_tenors_indexed,"matching_indices")]
mapped_IR_sens_summed[is.na(V1),V1:=0]
ir_charge = reg_data$sa_cva_multiplier*sqrt((mapped_IR_sens_summed$V1*IR_RW)%*%(data.matrix(cormat[1:(nrow(cormat)-1),2:(ncol(cormat)-1)])%*%(mapped_IR_sens_summed$V1*IR_RW)))
# CS part
cormat = superv$CS_cormat_by_tenor
superv_tenors = cormat[,1]
matching_indices = findInterval(cva_sensitivities$CS_tenors, superv_tenors)
mapped_CS_sens = data.table(cbind(cva_sensitivities$CS_delta, matching_indices))
mapped_CS_sens_summed = mapped_CS_sens[,sum(V1), by=matching_indices]
superv_tenors_indexed = data.table(superv_tenors = superv_tenors,matching_indices = seq(1,length(superv_tenors)))
mapped_CS_sens_summed = setkey(mapped_CS_sens_summed,"matching_indices")[setkey(superv_tenors_indexed,"matching_indices")]
mapped_CS_sens_summed[is.na(V1),V1:=0]
cs_charge = reg_data$sa_cva_multiplier*superv_rw*sqrt((mapped_CS_sens_summed$V1)%*%(data.matrix(cormat[,2:(ncol(cormat))])%*%(mapped_CS_sens_summed$V1)))
cva_capital_charge = list()
cva_capital_charge$IR_charge = ir_charge
cva_capital_charge$CS_charge = cs_charge
cva_capital_charge$Total_charge = ir_charge + cs_charge
}else
{stop('cva_framework can be either "BA-CVA" or "SA-CVA" or "STD-CVA". Please correct your input')}
return(cva_capital_charge)
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/calcCVACapital.R |
#' Calculates the default capital charge using the advanced IRB methodology and the stressed R
#' @title Calculates the Default Capital Charge
#' @param trades The full list of the Trade Objects
#' @param reg_data A list containing data related to the regulatory calculations (for example the regulatory probability-of-default, the regulatory loss-given-default etc)
#' @param effective_maturity The effective maturity of the trades of the netting set
#' @param EAD The Exposure-At-Default of the trades as per the selected regulatory framework
#' @return The default capital charge
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#'
calcDefCapital = function(trades,EAD, reg_data, effective_maturity)
{
R_bII = 0.12*(1-exp(-50*reg_data$PD_cpty))/(1-exp(-50))+0.24*(1-(1-exp(-50*reg_data$PD_cpty))/(1-exp(-50)))
R_stressed = 1.25*R_bII
b = (0.11852-0.05478*log(reg_data$PD_cpty))^2
K = (pnorm((qnorm(reg_data$PD_cpty)/sqrt(1-R_stressed) + sqrt(R_stressed/(1-R_stressed))*qnorm(0.999)))-reg_data$PD_cpty)*(1+(effective_maturity-2.5)*b)/(1-1.5*b)
default_capital_charge = 0.08*reg_data$LGD*K*EAD
return(default_capital_charge)
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/calcDefCapital.R |
#' Calculates the Exposure-At-Default (EAD) based on the given regulatory framework. It supports the CEM, IMM and (simplified) SA-CCR frameworks
#' @title Calculates the Exposure-At-Default (EAD)
#' @param trades The full list of the Trade Objects
#' @param framework Specifies the regulatory framework used in the calculations. It can take the values of 'IMM', 'CEM', 'SA-CCR'
#' @param sa_ccr_simplified (Optional) Specifies whether the standard SACCR or its simplified version or the OEM will be implemented. It can take the values of '', 'simplified', 'OEM'
#' @param CSA The margin agreement with the counterparty
#' @param collateral The amount of collaterals currently exchanged with the counterparty
#' @param EEE A vector containing the effective expected exposure against the counterparty
#' @param time_points The timepoints that the analysis is performed on
#' @return The Exposure-At-Default
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#'
calcEADRegulatory = function(trades, framework, sa_ccr_simplified="", CSA, collateral, EEE, time_points)
{
if(framework=='CEM')
{
addon_table = HashTable('AddonTable.csv',"numeric","numeric")
MtM_Vector <- as.numeric(lapply(trades, function(x) x$MtM))
maturity_vector <- as.numeric(lapply(trades, function(x) x$Ei))
NGR = CalcNGR(MtM_Vector)
addon = rep(0,length(maturity_vector))
for(i in 1:length(maturity_vector))
addon[i] = addon_table$FindIntervalValue(maturity_vector[i])
addon_amount = (0.4 + 0.6*NGR)*sum(addon)
EAD = max(max(sum(MtM_Vector),0)+addon_amount-as.numeric(!is.null(CSA$IM_cpty))*CSA$IM_cpty,0)
} else if(framework=='SA-CCR')
{
if(sa_ccr_simplified=='')
{
simplified = FALSE;
OEM = FALSE;
}else if(sa_ccr_simplified=='simplified')
{
simplified = TRUE;
OEM = FALSE;
}else if(sa_ccr_simplified=='OEM')
{
simplified = TRUE;
OEM = TRUE;
}else
{
simplified = FALSE;
OEM = FALSE;
}
requireNamespace("SACCR")
# calculating the maturity factor
MF = CSA$CalcMF(simplified = simplified)
# calculating the add-on
trades_tree = SACCR::CreateTradeGraph(trades)
trades_tree <- SACCR::CalcAddon(trades_tree, MF, simplified = simplified, OEM = OEM)
# calculating the RC and the V-c amount
rc_values <- SACCR::CalcRC(trades, CSA, list(collateral), simplified = simplified)
trades_tree$`Replacement Cost` = rc_values
# calculating the PFE after multiplying the addon with a factor if V-C<0
PFE <- SACCR::CalcPFE(rc_values$V_C, Addon_Aggregate = trades_tree$addon, simplified = simplified)
# calculating the Exposure-at-Default
EAD <- SACCR::CalcEAD(rc_values$RC, PFE)
} else if(framework=='IMM')
{ EAD = 1.4*mean(EEE[time_points<=1])}
if(framework=='SA-CCR')
{ return(list(EAD_Value = EAD, Exposure_Tree = trades_tree))
}else{return(EAD)}
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/calcEADRegulatory.R |
#' Calculates the effective maturity based on the specified regulatory framework
#' @title Calculates the Effective Maturity
#' @param trades The full list of the Trade Objects
#' @param framework Specifies the regulatory framework used in the calculations. It can take the values of 'IMM', 'CEM', 'SA-CCR'
#' @param simulated_exposure The exposure profile list containing the EE, EEE etc
#' @param time_points The timepoints that the analysis is performed on
#' @return The effective maturity of the trade set
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#'
calcEffectiveMaturity = function(trades, time_points, framework, simulated_exposure)
{
if(framework == "IMM")
{ effective_maturity = max(1,min( sum(simulated_exposure[time_points>1]*diff(time_points[time_points>=1]))/sum(simulated_exposure[time_points<1]*diff(time_points[time_points<=1])),5))
}else
{
Notional_vector = as.numeric(lapply(trades, function(x) x$Notional))
Maturity_vector = as.numeric(lapply(trades, function(x) x$Ei))
effective_maturity = max(1, sum(Notional_vector*Maturity_vector)/sum(Notional_vector))
}
return(effective_maturity)
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/calcEffectiveMaturity.R |
#' Calculates the capital valuation adjustment by computing the default capital charge and the CVA capital charge and applying the required return-on-capital
#' @title Calculates the Capital Valuation Adjustment (KVA)
#' @param CSA The margin agreement with the counterparty
#' @param collateral The current amount of collaterals currently exchanged with the counterparty
#' @param trades The full list of the Trade Objects
#' @param reg_data A list containing data related to the regulatory calculations (for example the 'framework' member variable can be 'IMM','SACCR','CEM')
#' @param time_points The timepoints that the analysis is performed on
#' @param EAD The Exposure-at-default calculated based on the prescribed framework as appearing in the 'reg_data'
#' @param effective_maturity The effective maturity of the trades performed with a specific counterparty
#' @param ignore_def_charge if set to true the default capital charge is set to zero
#' @return The capital valuation adjustment (KVA)
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#'
calcKVA = function(CSA, collateral, trades, reg_data, time_points, EAD, effective_maturity, ignore_def_charge = TRUE)
{
if(ignore_def_charge)
{ def_capital_charge = 0
}else
{def_capital_charge = calcDefCapital(trades,EAD, reg_data, effective_maturity)}
# cva_capital_charge = calcCVACapital(trades, EAD, reg_data$cpty_rating, effective_maturity)
# KVA = -(def_capital_charge+cva_capital_charge)*0.5*sqrt(effective_maturity)*reg_data$return_on_capital
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/calcKVA.R |
.onAttach <- function(libname, pkgname) {
packageStartupMessage("For commercial usage or to report any bugs & enhancement requests, please contact [email protected]")
} | /scratch/gouwar.j/cran-all/cranData/xVA/R/onLoad.R |
#' Calculates the xVA values (CVA, DVA, FVA, FBA, MVA, KVA)
#'
#' @title Calculates the xVA values
#' @param trades The full list of the Trade Objects
#' @param CSA The margin agreement with the counterparty
#' @param collateral The amount of collateral currently exchanged with the counterparty
#' @param sim_data A list containing data related to the calculation of simulated exposures (for example the model parameters and the number of simulations)
#' @param reg_data A list containing data related to the regulatory calculations (for example the 'ccr_framework' member variable can be 'IMM','SACCR','CEM')
#' @param credit_curve_PO The credit curve of the processing organization
#' @param credit_curve_cpty The credit curve of the processing organization
#' @param funding_curve A curve containing the credit spread for the funding of the collateral
#' @param spot_rates The spot rates curve
#' @param cpty_LGD The loss-given-default of the counterparty
#' @param PO_LGD The loss-given-default of the processing organization
#' @param no_simulations if true, no simulated exposure will be generated and the regulatory framework should be SA-CCR
#' @return A list containing the xVA values and the cva capital charge
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#' @references Gregory J., The xVA Challenge, 2015, Wiley
#'
xVACalculator = function(trades, CSA, collateral, sim_data, reg_data, credit_curve_PO, credit_curve_cpty, funding_curve, spot_rates, cpty_LGD, PO_LGD, no_simulations)
{
if(no_simulations&®_data$ccr_framework=='IMM') stop('You have chosen not to use any simulations so IMM is not possible - please change the regulatory framework to SA-CCR')
maturity <- max(as.numeric(lapply(trades, function(x) x$Ei)))
time_points = GenerateTimeGrid(CSA, maturity)
num_of_points = length(time_points)
initial_ir_rates = spot_rates$Rates
spot_curve = spot_rates$CalcInterpPoints(time_points,"linear")
initial_cs_rates = credit_curve_cpty$Rates
cpty_spread = credit_curve_cpty$CalcInterpPoints(time_points)
PO_spread = credit_curve_PO$CalcInterpPoints(time_points)
funding_spread = funding_curve$CalcInterpPoints(time_points)
superv = LoadSupervisoryCVAData()
discount_factors = exp(-time_points*spot_curve)
PD_cpty = CalcPD(cpty_spread,cpty_LGD,time_points)
PD_PO = CalcPD(PO_spread,PO_LGD,time_points)
PD_FVA = CalcPD(funding_spread,1,time_points)
if(!no_simulations)
{ exposure_profile = CalcSimulatedExposure(discount_factors, time_points, spot_curve, CSA, trades, sim_data, reg_data$ccr_framework)
}else
{
exposure_profile = list()
exposure_profile$EE = 0
exposure_profile$EEE = 0
}
EAD = calcEADRegulatory(trades, reg_data$ccr_framework, reg_data$sa_ccr_simplified, CSA, collateral, exposure_profile$EEE, time_points)
effective_maturity = calcEffectiveMaturity(trades, time_points, reg_data$ccr_framework, exposure_profile$EE)
xVA = list()
xVA$KVA = calcKVA(CSA, collateral, trades, reg_data, time_points, EAD$EAD_Value, effective_maturity, reg_data$ignore_def_charge)
if(!no_simulations)
{
xVA$CVA_simulated = CalcVA(exposure_profile$EE, discount_factors, PD_cpty, cpty_LGD)
xVA$DVA_simulated = CalcVA(exposure_profile$NEE, discount_factors, PD_PO, PO_LGD)
}
if(reg_data$cva_framework=='SA-CVA'&&no_simulations) stop('Please disable the no_simulations flag when selecting the SA-CVA model')
if(reg_data$cva_framework=='SA-CVA')
{
bp = 0.0001
cva_sensitivities = list()
cva_sensitivities$CS_delta = rep(0,length(credit_curve_cpty$Tenors))
cva_sensitivities$CS_tenors = credit_curve_cpty$Tenors
cva_sensitivities$IR_delta = rep(0,length(spot_rates$Tenors))
cva_sensitivities$IR_tenors = spot_rates$Tenors
for(i in 1:length( credit_curve_cpty$Tenors))
{
credit_curve_cpty$Rates = initial_cs_rates
credit_curve_cpty$Rates[i] = credit_curve_cpty$Rates[i]+1
cpty_spread_bumped = credit_curve_cpty$CalcInterpPoints(time_points)
PD_cpty_bumped = CalcPD(cpty_spread_bumped,cpty_LGD,time_points)
PD_cpty_bumped[PD_cpty_bumped<PD_cpty] = PD_cpty[PD_cpty_bumped<PD_cpty]
cva_sensitivities$CS_delta[i] = -(CalcVA(exposure_profile$EE, discount_factors, PD_cpty_bumped, cpty_LGD) - xVA$CVA_simulated)/bp
}
for(i in 1:length(spot_rates$Rates))
{
spot_rates$Rates = initial_ir_rates
spot_rates$Rates[i] = spot_rates$Rates[i] + bp
spot_curve_bumped = spot_rates$CalcInterpPoints(time_points,"linear")
discount_factors_bumped = exp(-time_points*spot_curve_bumped)
exposure_profile_bumped = CalcSimulatedExposure(discount_factors_bumped, time_points, spot_curve_bumped, CSA, trades, sim_data, reg_data$ccr_framework)
cva_sensitivities$IR_delta[i] = -(CalcVA(exposure_profile_bumped$EE, discount_factors_bumped, PD_cpty, cpty_LGD) - xVA$CVA_simulated)/bp
}
}
xVA$cva_capital_charge = calcCVACapital(trades, EAD, reg_data, superv, effective_maturity, cva_sensitivities)
if(reg_data$ccr_framework=='SA-CCR')
{
pos_exposure = ifelse(EAD$Exposure_Tree$`Replacement Cost`$V_C+EAD$Exposure_Tree$addon<0,0,EAD$Exposure_Tree$`Replacement Cost`$V_C+EAD$Exposure_Tree$addon)
neg_exposure = ifelse(EAD$Exposure_Tree$`Replacement Cost`$V_C-EAD$Exposure_Tree$addon>0,0,(ifelse(EAD$Exposure_Tree$`Replacement Cost`$V_C<0,EAD$Exposure_Tree$`Replacement Cost`$V_C,-EAD$Exposure_Tree$`Replacement Cost`$V_C)-EAD$Exposure_Tree$addon))
pd_aggregate = 0
for(i in 1:ceiling(effective_maturity))
{ pd_aggregate = pd_aggregate + reg_data$PD_cpty * (1 - reg_data$PD_cpty)^(i - 1)}
xVA$CVA_SACCR = -pos_exposure*pd_aggregate*cpty_LGD
pd_aggregate = 0
for(i in 1:ceiling(effective_maturity))
{ pd_aggregate = pd_aggregate + reg_data$PD_PO * (1 - reg_data$PD_PO)^(i - 1)}
xVA$DVA_SACCR = -neg_exposure*pd_aggregate*PO_LGD
pd_aggregate = 0
for(i in 1:ceiling(effective_maturity))
{ pd_aggregate = pd_aggregate + reg_data$PD_cpty * (1 - reg_data$PD_FVA)^(i - 1)}
xVA$FCA_SACCR = -pos_exposure*pd_aggregate
xVA$FBA_SACCR = -neg_exposure*pd_aggregate
xVA$MVA_SACCR = xVA$FCA_SACCR*2*sqrt(reg_data$mva_days/(250*maturity))*qnorm(reg_data$mva_percentile)/dnorm(0)
}
if(!no_simulations)
{
xVA$FCA_simulated = CalcVA(exposure_profile$EE, discount_factors, PD_FVA)
xVA$FBA_simulated = CalcVA(exposure_profile$NEE, discount_factors, PD_FVA)
xVA$MVA_simulated = xVA$FCA_simulated*2*sqrt(reg_data$mva_days/(250*maturity))*qnorm(reg_data$mva_percentile)/dnorm(0)
}
return(xVA)
} | /scratch/gouwar.j/cran-all/cranData/xVA/R/xVACalculator.R |
#' Calculates the xVA values for a simple example containing two IR swaps.
#' @title xVA calculation example
#' @return A list with the values of various valuations' adjustments
#' @export
#' @author Tasos Grivas <tasos@@openriskcalculator.com>
#' @examples
#'
#' ## run the example
#'
#' xVACalculatorExample()
#'
xVACalculatorExample = function()
{
# ccr_framework can be either "IMM" or "CEM" or "SA-CCR"
# cva_framework can be either "BA-CVA" or "SA-CVA" or "STD-CVA"
reg_data = list(ccr_framework = "SA-CCR", sa_ccr_simplified = "", cva_framework = "SA-CVA", sa_cva_multiplier = 1.2, cpty_sector = "Sovereigns including central banks and multilateral development banks",
ignore_def_charge = TRUE, PD_cpty = 0.002, PD_PO = 0.005, PD_FVA = 0.001, LGD = 0.45, return_on_capital = 0.03, cpty_rating = 'A',
mva_days = 10, mva_percentile = 0.99)
sim_data = list(PFE_Percentile = 0.9, num_of_sims = 50, mean_reversion_a = 0.001, volatility = 0.01)
cpty_LGD = 0.45
PO_LGD = 0.45
tr1 = Trading::IRDSwap(external_id ="ext1",Notional=1,MtM = 0.045, Currency="USD",Si=0,Ei=7,BuySell='Sell', pay_leg_rate = 0.05)
tr2 = Trading::IRDSwap(external_id ="ext2",Notional=1,MtM = -0.065, Currency="USD",Si=0,Ei=10,BuySell='Buy', pay_leg_rate = 0.05)
no_simulations = FALSE
trades = list(tr1,tr2)
credit_curve_cpty = Trading::Curve(Tenors=c(1,2,3,4,5,6,10),Rates=c(3,10,20,40,66,99,150))
credit_curve_PO = Trading::Curve(Tenors=c(1,2,3,4,5,6,10),Rates=c(4,11,23,47,76,110,160))
funding_curve = Trading::Curve(Tenors=c(1,2,3,4,5,6,10),Rates=c(4,17,43,47,76,90,110))
spot_rates = Trading::Curve()
spot_rates$PopulateViaCSV('spot_rates.csv')
spot_rates$Rates = spot_rates$Rates/10000
csa = Trading::CSA(ID="csa_1",thres_cpty = 0.07, thres_PO = 0.1, IM_cpty = 0.03, IM_PO = 0.02, MTA_cpty = 0.007,
MTA_PO = 0.01, mpor_days = 10, remargin_freq = 90, Values_type="Actual")
current_collateral = Trading::Collateral(ID="col_1",csa_id="csa_1",Amount=0.03,type="VariationMargin")
xVA = xVACalculator(trades, csa, current_collateral, sim_data, reg_data, credit_curve_PO, credit_curve_cpty, funding_curve, spot_rates, cpty_LGD, PO_LGD, no_simulations)
return(xVA)
}
| /scratch/gouwar.j/cran-all/cranData/xVA/R/xVACalculatorExample.R |
#' Simulated Admixture Data
#'
#' A dataset containing simulated admixture data of 600 observations.
#'
#' @format A data frame with 600 rows and 8 variables:
#' \describe{
#' \item{\code{acc}}{Accession identifier}
#' \item{\code{country}}{Country where plant material was collected}
#' \item{\code{species}}{Name of species}
#' \item{\code{K1},\code{K2},\code{K3},\code{K4},\code{K5}}{Admixture coefficients; expresses the proportions of the respective ancestries. Sum up to 1.}
#' }
#' @source Data simulated for this package; for code see: \url{https://github.com/SpaceCowboy-71/xadmix/blob/main/data-raw/xadmixture.R}
#' @examples
#' # load simulated admixture data
#' data("xadmixture")
#'
#' # create a subset of the data
#' xadmixture_sub <- admix_subset(xadmixture,
#' country = c("GBR", "FRA"),
#' anc = c("K1", "K2"),
#' pct = c(0.02, 0.2))
#'
#' # generate a grouped & sorted stacked barplot
#' admix_barplot(xadmixture_sub,
#' K = 4:ncol(xadmixture),
#' sortkey = "K1",
#' grouping = "country",
#' palette = "turbo")
"xadmixture" | /scratch/gouwar.j/cran-all/cranData/xadmix/R/data.R |
#' Admixture Data Stacked Barplot
#'
#' Stacked barplot optimized for admixture data.
#' @param data Data frame containing the admixture data.
#' @param K Positions of the columns containing the ancestry percentages in the provided data frame; default is second to last column.
#' @param individuals Position of the column with the names for the x-axis; default is the first column.
#' @param sortkey Name of the column containing ancestry percentages to sort the stacked barplot with.
#' @param grouping Name of the column by which the stacked bars are to be grouped.
#' @param palette Either a color palette object, or a string to use one of the predefined color palettes ("viridis", "turbo", "alternating"); default is a modified ggplot palette.
#' @param names Whether to show the x-axis bar labels or not; default is "TRUE".
#' @param xlab A label for the x-axis.
#' @param ylab A label for the y-axis.
#' @param main A main title for the plot.
#' @param noclip Directly draw the plot, with clipping removed from elements. Then function does not return an object; default is set to "FALSE". Setting to "TRUE" may require launching a new R graphics device.
#' @return A ggplot object of the stacked barplot.
#' @examples
#' # load simulated admixture data
#' data("xadmixture")
#'
#' # for data frame with ancestries (K) in fourth to last column,
#' # without showing bar labels
#' admix_barplot(xadmixture,
#' K = 4:ncol(xadmixture),
#' names = FALSE
#' )
#'
#' # grouping data by column "country",
#' # and sorting each group by ancestry column "K1"
#' admix_barplot(xadmixture,
#' K = 4:ncol(xadmixture),
#' grouping = "country",
#' sortkey = "K1",
#' names = FALSE
#' )
#'
#' # changing color palette to "turbo" from package 'viridis',
#' admix_barplot(xadmixture,
#' K = 4:ncol(xadmixture),
#' palette = "turbo",
#' names = FALSE
#' )
#'
#' # removing title and changing axis labels text
#' admix_barplot(xadmixture,
#' K = 4:ncol(xadmixture),
#' main = "",
#' xlab = "Accessions",
#' ylab = "Ancestry [%]",
#' names = FALSE
#' )
#'
#' # directly output grouped plot with clipping removed from elements
#' # (useful if there are groups with a low number of observations)
#' # create a subset of the data
#' xadmixture_sub <- admix_subset(xadmixture,
#' anc = c("K3", "K4"),
#' pct = c(0.3, 0.2))
#' # generate a grouped & sorted stacked barplot
#' # setting "noclip" to "TRUE" may require opening a new graphics device
#' dev.new()
#' admix_barplot(xadmixture_sub,
#' K = 4:ncol(xadmixture),
#' sortkey = "K5",
#' grouping = "country",
#' palette = "viridis",
#' names = FALSE,
#' noclip = TRUE)
#' dev.off()
#' @import dplyr
#' @import forcats
#' @import ggplot2
#' @import viridis
#' @importFrom tidyr pivot_longer
#' @importFrom stringr str_sort
#' @importFrom methods hasArg
#' @importFrom rlang .data
#' @export
admix_barplot <- function(data, K = 2:ncol(data), individuals = 1, sortkey = NULL, grouping = NULL, palette = "default",
names = TRUE, xlab = "Individuals", ylab = "Ancestry", main = "Admixture Plot", noclip = FALSE) {
# throw error if there are now observations
if (nrow(data) == 0) {
stop("No observations found!")
}
# throw error if ancestry columns are not of class numeric
if (!is.numeric(as.matrix(data[, K]))) {
stop("Please select only numeric columns!")
}
# rename a column to "individual"; default is first column
names(data)[individuals] <- "individual"
# convert to tidy format for ggplot
data_tidy <- pivot_longer(data, K, names_to = "ancestry", values_to = "percentage")
# sort the bars descending, using sortkey arg
if (hasArg(sortkey)) {
df_sortpos <- data_tidy %>%
filter(.data$ancestry == sortkey) %>%
arrange(desc(.data$percentage))
data_tidy$individual <- factor(data_tidy$individual, levels = df_sortpos$individual)
}
# fct_relevel is used to apply str_sort(numeric = TRUE) on factors, then fct_rev to reverse the order
str_sort_numeric <- function(x) {
return(str_sort(x, numeric = TRUE))
}
plt <- ggplot(data_tidy, aes(.data$individual, .data$percentage, fill = fct_rev(fct_relevel(.data$ancestry, str_sort_numeric)))) +
geom_col(width = 1) +
theme_minimal() + # minimal theme to remove tick marks etc.
labs(x = xlab, y = ylab, title = main) + # assign labels using arguments
theme( # adjust title position and remove grid
plot.title = element_text(hjust = 0.04, vjust = -5),
panel.grid = element_blank()
) +
# make x-axis names toggable via argument
if (names == TRUE) {
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
)
} else {
theme(
axis.text.x = element_blank(),
)
}
# change color palette
# check first whether "palette" arg is single string to use premade palette
if (is.character(palette) & length(palette) == 1) {
if (palette == "viridis") {
# viridis for colorblind support
plt <- plt + scale_fill_viridis(discrete = TRUE, name = "")
} else if (palette == "turbo") {
# much improved rainbow color map
plt <- plt + scale_fill_viridis(discrete = TRUE, name = "", option = "turbo")
} else if (palette == "default") {
# default with slightly increased chromaticity and reduced luminance
plt <- plt + scale_fill_hue(c = 130, l = 55, name = "")
} else if (palette == "alternating") {
hexcols <- c(
"#821E00", "#C08D00", "#AAF300", "#00D647", "#007294", "#1F007B", "#600082", "#8A007E",
"#E35500", "#FFC115", "#C4FF3B", "#24FF6D", "#00BAF2", "#3800DF", "#A600E3", "#EA00D7"
)
plt <- plt + scale_fill_manual(values = hexcols, name = "")
}
# if no single string was provided, use "palette" arg as palette object
} else {
plt <- plt + scale_fill_manual(values = palette, name = "")
}
# group variables by grouping arg
if (hasArg(grouping)) {
plt <- plt + facet_grid(~ fct_inorder(data_tidy[[grouping]]), switch = "x", scales = "free", space = "free_x")
}
# disable clipping for all elements if argument is set to TRUE
# might require to reload graphics device with dev.new()
if (noclip) {
pg <- ggplotGrob(plt)
for (i in which(grepl("*", pg$layout$name))) {
pg$grobs[[i]]$layout$clip <- "off"
}
grid::grid.draw(pg)
} else {
return(plt)
}
}
| /scratch/gouwar.j/cran-all/cranData/xadmix/R/plots.R |
#' Admixture Data Subsetting
#'
#' Subset function optimized for admixture data.
#' Filters for the percentages of any number of ancestry (K) columns and prints progress. Also allows passing additional arguments to filter columns with.
#' @param data Data frame containing the admixture data.
#' @param anc Vector of ancestry column names to use for pairwise subsetting with percentage vector. Must be of same length as the supplied percentage vector.
#' @param pct Vector of percentage values to use for pairwise subsetting with ancestry column name vector. Only ancestries with values above the percentage are kept.
#' @param comparison What comparison operator to use for the subsetting. Can either be "greater" or "less"; default is "greater". Also accepts "gt", "lt", ">" and "<".
#' @param quiet Whether to print progress or not; default is "FALSE".
#' @param ... Variable number of additional vectors for subsetting. Looking at the column with argument name, keeps only those observations with values which are elements of the argument vector.
#' @return A subset of the provided data frame.
#' @examples
#' # load simulated admixture data
#' data("xadmixture")
#'
#' # keep only observations with K1 > 0.1 and K2 > 0.01
#' subset1 <- admix_subset(xadmixture,
#' anc = c("K1", "K2"),
#' pct = c(0.1, 0.01))
#'
#' # keep only observations with K2 < 0.4 and K3 < 0.1
#' subset2 <- admix_subset(xadmixture,
#' anc = c("K2", "K3"),
#' pct = c(0.4, 0.1),
#' comparison = "less")
#'
#' # keep only observations with values "GBR" or "FRA" in column
#' # "country" and values "lorem" or "dolor" in column "species"
#' subset3 <- admix_subset(xadmixture,
#' country = c("GBR", "FRA"),
#' species = c("lorem", "dolor"))
#'
#' # keep only observations with K1 > 0.1 and K4 < 0.3,
#' # without printing progress; subsets can be chained
#' # using the pipe operator from package `magrittr`
#' library(magrittr)
#' subset4 <- admix_subset(xadmixture,
#' anc = "K1",
#' pct = 0.1,
#' quiet = TRUE) %>%
#' admix_subset(anc = "K4",
#' pct = 0.3,
#' comparison = "less",
#' quiet = TRUE)
#' @importFrom magrittr %>%
#' @importFrom dplyr filter
#' @importFrom stats na.omit
#' @importFrom methods hasArg
#' @export
admix_subset <- function(data, anc = NULL, pct = NULL, comparison = "greater", quiet = FALSE, ...) {
# ancestries <anc> and percentages <pct> can be vectors
# however, they must be of the same length!
# the first entries each form a pair, then the second ones...
# Error handling - check for same length vectors
if (length(anc) != length(pct)) stop("Ancestry and percentage vectors must be of same length!")
# reassign data arg for clarity
asub <- data
# print total observations
if (!quiet) {
cat("observations:", nrow(asub), "\n")
}
args <- list(...) # get additional arguments
arg_names <- names(args) # get argument names
# use additional args for subsetting
if (length(arg_names) > 0) {
for (i in 1:length(arg_names)) {
asub <- asub %>% filter(asub[[arg_names[i]]] %in% args[[i]])
# print progress
if (!quiet) {
cat("keeping only specified values in col:", arg_names[i], "\n")
cat("\tobservations left after this step:", nrow(asub), "\n")
}
}
}
# loop over all ancestry-percentage pairs,
# only selecting those with percentage higher or lower than cutoff
# generating one subset
if (hasArg(anc) && hasArg(pct)) {
for (i in 1:length(anc)) {
if (comparison == "gt" || comparison == "greater" || comparison == ">") {
asub <- asub %>% filter(asub[[anc[i]]] > pct[i])
compc <- ">"
} else if (comparison == "lt" || comparison == "less" || comparison == "<") {
asub <- asub %>% filter(asub[[anc[i]]] < pct[i])
compc <- "<"
} else {
stop("comparison must be either 'gt' or 'lt'")
}
asub <- na.omit(asub)
# print progress
if (!quiet) {
cat(i, ". subset, ", anc[i], " ", compc, " ", pct[i], "\n", sep = "")
cat("\tobservations:", nrow(asub), "\n")
}
}
}
return(asub)
}
| /scratch/gouwar.j/cran-all/cranData/xadmix/R/tools.R |
## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.retina = 2,
fig.width = 480/72,
fig.asp = 0.7,
dev.args = list(type = "cairo-png")
)
## ----setup--------------------------------------------------------------------
library(xadmix)
## -----------------------------------------------------------------------------
data("xadmixture")
str(xadmixture)
# number of observations per country
table(xadmixture$country)
# number of observations per species
table(xadmixture$species)
## -----------------------------------------------------------------------------
# keep only observations with K1 > 0.15 and K2 > 0.01
subset1 <- admix_subset(xadmixture,
anc = c("K1", "K2"),
pct = c(0.15, 0.01))
# keep only observations with K2 < 0.1 and K3 < 0.1
subset2 <- admix_subset(xadmixture,
anc = c("K2", "K3"),
pct = c(0.1, 0.1),
comparison = "less")
# filtering for countries and species
subset3 <- admix_subset(xadmixture,
country = c("GBR", "FRA"),
species = c("lorem", "dolor"))
## -----------------------------------------------------------------------------
library(magrittr)
# keep only observations with K1 > 0.1 and K4 < 0.3,
# without printing subset progress
subset4 <- admix_subset(xadmixture,
anc = "K1",
pct = 0.1,
quiet = TRUE) %>%
admix_subset(anc = "K1",
pct = 0.3,
comparison = "less",
quiet = TRUE)
# print number of observations for comparison
nrow(xadmixture)
nrow(subset4)
## -----------------------------------------------------------------------------
# ancestries (K) are in the fourth to last column,
# and plotted without showing bar labels
admix_barplot(xadmixture,
K = 4:ncol(xadmixture),
names = FALSE
)
## -----------------------------------------------------------------------------
# grouping data by column "country",
# and sorting each group by ancestry column "K1"
admix_barplot(subset1,
K = 4:ncol(xadmixture),
grouping = "country",
sortkey = "K1"
)
# changing color palette to "turbo" from package 'viridis',
admix_barplot(subset2,
K = 4:ncol(xadmixture),
palette = "turbo",
grouping = "species",
sortkey = "K4"
)
## -----------------------------------------------------------------------------
# removing title and changing axis labels text
admix_barplot(subset3,
K = 4:ncol(xadmixture),
main = "",
xlab = "Accessions",
ylab = "Ancestry [%]",
palette = "alternating",
sortkey = "K1",
names = FALSE
)
## -----------------------------------------------------------------------------
# directly output grouped plot with clipping removed from elements
# (useful if there are groups with a low number of observations)
subset5 <- admix_subset(xadmixture,
anc = c("K3", "K4"),
pct = c(0.3, 0.2),
quiet = TRUE)
## -----------------------------------------------------------------------------
# noclip set to "TRUE"
admix_barplot(subset5,
K = 4:ncol(xadmixture),
sortkey = "K5",
grouping = "country",
palette = "viridis",
names = FALSE,
main = "Noclip on",
noclip = TRUE)
# noclip set to "FALSE"
admix_barplot(subset5,
K = 4:ncol(xadmixture),
sortkey = "K5",
grouping = "country",
palette = "viridis",
names = FALSE,
main = "Noclip off",
noclip = FALSE)
| /scratch/gouwar.j/cran-all/cranData/xadmix/inst/doc/xadmix-manual.R |
---
title: "Manual - `xadmix`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Manual - `xadmix`}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.retina = 2,
fig.width = 480/72,
fig.asp = 0.7,
dev.args = list(type = "cairo-png")
)
```
First, let's load the package. If you haven't installed it yet, you can do so with the `install.packages("xadmix")` command to get the latest stable release from *CRAN*. Alternatively, you can install the latest development release from GitHub: `devtools::install_github("SpaceCowboy-71/xadmix")`. This, however, requires the package `devtools`.
```{r setup}
library(xadmix)
```
## Simulated Dataset
The `xadmix` package provides a dummy dataset ("*xadmixture*") containing simulated genetic admixture data. Each observation has an accession identifier, the country where the plant material was collected, an entry for the species and five admixture coefficients, *K*. The values of these ancestries sum up to 1.
```{r}
data("xadmixture")
str(xadmixture)
# number of observations per country
table(xadmixture$country)
# number of observations per species
table(xadmixture$species)
```
## Subsetting
`xadmix` comes with an optimized data subsetting function, `admix_subset()`. It enables filtering of the data for ancestry (*K*) percentages greater or less than a certain value. Additionally, any number of columns can be filtered for values supplied in a vector. By default, it also prints the progress after each subsetting step.
Multiple ancestries along with their percentages can be passed as argument vectors. Subsetting is then done pairwise, filtering the first ancestry by the first pecentage, then the second ones and so on. Some examples:
```{r}
# keep only observations with K1 > 0.15 and K2 > 0.01
subset1 <- admix_subset(xadmixture,
anc = c("K1", "K2"),
pct = c(0.15, 0.01))
# keep only observations with K2 < 0.1 and K3 < 0.1
subset2 <- admix_subset(xadmixture,
anc = c("K2", "K3"),
pct = c(0.1, 0.1),
comparison = "less")
# filtering for countries and species
subset3 <- admix_subset(xadmixture,
country = c("GBR", "FRA"),
species = c("lorem", "dolor"))
```
Subsets can be chained using the pipe operator (`%>%`) from package `magrittr`. This way, filtering for percentages greater and less than certain values is possible.
By setting the argument `quiet` to `TRUE`, no subset progress will be printed.
```{r}
library(magrittr)
# keep only observations with K1 > 0.1 and K4 < 0.3,
# without printing subset progress
subset4 <- admix_subset(xadmixture,
anc = "K1",
pct = 0.1,
quiet = TRUE) %>%
admix_subset(anc = "K1",
pct = 0.3,
comparison = "less",
quiet = TRUE)
# print number of observations for comparison
nrow(xadmixture)
nrow(subset4)
```
## Admixture Plots
`xadmix` also comes with a user-friendly function for generating pretty stacked barplots, optimized to use with admixture data.
If the dataset were to contain only the accession numbers in the first column and ancestry percentages in subsequent columns, the function could be used without any further arguments.
However, the `xadmixture` dataset contains additional columns. Therefore, the columns for all *K*`s have to be selected by passing an argument. An example plotting the whole dataset:
```{r}
# ancestries (K) are in the fourth to last column,
# and plotted without showing bar labels
admix_barplot(xadmixture,
K = 4:ncol(xadmixture),
names = FALSE
)
```
### Grouped Stacked Barplots & Customized Appearance
More information can be gained by looking at the subsets generated above:
```{r}
# grouping data by column "country",
# and sorting each group by ancestry column "K1"
admix_barplot(subset1,
K = 4:ncol(xadmixture),
grouping = "country",
sortkey = "K1"
)
# changing color palette to "turbo" from package 'viridis',
admix_barplot(subset2,
K = 4:ncol(xadmixture),
palette = "turbo",
grouping = "species",
sortkey = "K4"
)
```
```{r}
# removing title and changing axis labels text
admix_barplot(subset3,
K = 4:ncol(xadmixture),
main = "",
xlab = "Accessions",
ylab = "Ancestry [%]",
palette = "alternating",
sortkey = "K1",
names = FALSE
)
```
### Noclip Feature
Sometimes the group labels can get cut off. When there are not enough observations in the group, the width of the grouped bars can be smaller than the width of the group label. `ggplot2` does not yet offer a flag to avoid this problem. In `xadmix`, however, there is an option to remove clipping altogether:
```{r}
# directly output grouped plot with clipping removed from elements
# (useful if there are groups with a low number of observations)
subset5 <- admix_subset(xadmixture,
anc = c("K3", "K4"),
pct = c(0.3, 0.2),
quiet = TRUE)
```
```{r}
# noclip set to "TRUE"
admix_barplot(subset5,
K = 4:ncol(xadmixture),
sortkey = "K5",
grouping = "country",
palette = "viridis",
names = FALSE,
main = "Noclip on",
noclip = TRUE)
# noclip set to "FALSE"
admix_barplot(subset5,
K = 4:ncol(xadmixture),
sortkey = "K5",
grouping = "country",
palette = "viridis",
names = FALSE,
main = "Noclip off",
noclip = FALSE)
```
<br />
<br />
<p style="text-align: center; font-size:16pt">♦</p>
<br />
| /scratch/gouwar.j/cran-all/cranData/xadmix/inst/doc/xadmix-manual.Rmd |
---
title: "Manual - `xadmix`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Manual - `xadmix`}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.retina = 2,
fig.width = 480/72,
fig.asp = 0.7,
dev.args = list(type = "cairo-png")
)
```
First, let's load the package. If you haven't installed it yet, you can do so with the `install.packages("xadmix")` command to get the latest stable release from *CRAN*. Alternatively, you can install the latest development release from GitHub: `devtools::install_github("SpaceCowboy-71/xadmix")`. This, however, requires the package `devtools`.
```{r setup}
library(xadmix)
```
## Simulated Dataset
The `xadmix` package provides a dummy dataset ("*xadmixture*") containing simulated genetic admixture data. Each observation has an accession identifier, the country where the plant material was collected, an entry for the species and five admixture coefficients, *K*. The values of these ancestries sum up to 1.
```{r}
data("xadmixture")
str(xadmixture)
# number of observations per country
table(xadmixture$country)
# number of observations per species
table(xadmixture$species)
```
## Subsetting
`xadmix` comes with an optimized data subsetting function, `admix_subset()`. It enables filtering of the data for ancestry (*K*) percentages greater or less than a certain value. Additionally, any number of columns can be filtered for values supplied in a vector. By default, it also prints the progress after each subsetting step.
Multiple ancestries along with their percentages can be passed as argument vectors. Subsetting is then done pairwise, filtering the first ancestry by the first pecentage, then the second ones and so on. Some examples:
```{r}
# keep only observations with K1 > 0.15 and K2 > 0.01
subset1 <- admix_subset(xadmixture,
anc = c("K1", "K2"),
pct = c(0.15, 0.01))
# keep only observations with K2 < 0.1 and K3 < 0.1
subset2 <- admix_subset(xadmixture,
anc = c("K2", "K3"),
pct = c(0.1, 0.1),
comparison = "less")
# filtering for countries and species
subset3 <- admix_subset(xadmixture,
country = c("GBR", "FRA"),
species = c("lorem", "dolor"))
```
Subsets can be chained using the pipe operator (`%>%`) from package `magrittr`. This way, filtering for percentages greater and less than certain values is possible.
By setting the argument `quiet` to `TRUE`, no subset progress will be printed.
```{r}
library(magrittr)
# keep only observations with K1 > 0.1 and K4 < 0.3,
# without printing subset progress
subset4 <- admix_subset(xadmixture,
anc = "K1",
pct = 0.1,
quiet = TRUE) %>%
admix_subset(anc = "K1",
pct = 0.3,
comparison = "less",
quiet = TRUE)
# print number of observations for comparison
nrow(xadmixture)
nrow(subset4)
```
## Admixture Plots
`xadmix` also comes with a user-friendly function for generating pretty stacked barplots, optimized to use with admixture data.
If the dataset were to contain only the accession numbers in the first column and ancestry percentages in subsequent columns, the function could be used without any further arguments.
However, the `xadmixture` dataset contains additional columns. Therefore, the columns for all *K*`s have to be selected by passing an argument. An example plotting the whole dataset:
```{r}
# ancestries (K) are in the fourth to last column,
# and plotted without showing bar labels
admix_barplot(xadmixture,
K = 4:ncol(xadmixture),
names = FALSE
)
```
### Grouped Stacked Barplots & Customized Appearance
More information can be gained by looking at the subsets generated above:
```{r}
# grouping data by column "country",
# and sorting each group by ancestry column "K1"
admix_barplot(subset1,
K = 4:ncol(xadmixture),
grouping = "country",
sortkey = "K1"
)
# changing color palette to "turbo" from package 'viridis',
admix_barplot(subset2,
K = 4:ncol(xadmixture),
palette = "turbo",
grouping = "species",
sortkey = "K4"
)
```
```{r}
# removing title and changing axis labels text
admix_barplot(subset3,
K = 4:ncol(xadmixture),
main = "",
xlab = "Accessions",
ylab = "Ancestry [%]",
palette = "alternating",
sortkey = "K1",
names = FALSE
)
```
### Noclip Feature
Sometimes the group labels can get cut off. When there are not enough observations in the group, the width of the grouped bars can be smaller than the width of the group label. `ggplot2` does not yet offer a flag to avoid this problem. In `xadmix`, however, there is an option to remove clipping altogether:
```{r}
# directly output grouped plot with clipping removed from elements
# (useful if there are groups with a low number of observations)
subset5 <- admix_subset(xadmixture,
anc = c("K3", "K4"),
pct = c(0.3, 0.2),
quiet = TRUE)
```
```{r}
# noclip set to "TRUE"
admix_barplot(subset5,
K = 4:ncol(xadmixture),
sortkey = "K5",
grouping = "country",
palette = "viridis",
names = FALSE,
main = "Noclip on",
noclip = TRUE)
# noclip set to "FALSE"
admix_barplot(subset5,
K = 4:ncol(xadmixture),
sortkey = "K5",
grouping = "country",
palette = "viridis",
names = FALSE,
main = "Noclip off",
noclip = FALSE)
```
<br />
<br />
<p style="text-align: center; font-size:16pt">♦</p>
<br />
| /scratch/gouwar.j/cran-all/cranData/xadmix/vignettes/xadmix-manual.Rmd |
#' An R Markdown output format for remark.js slides
#'
#' This output format produces an HTML file that contains the Markdown source
#' (knitted from R Markdown) and JavaScript code to render slides.
#' \code{tsukuyomi()} is an alias of \code{moon_reader()}.
#'
#' Tsukuyomi is a genjutsu to trap the target in an illusion on eye contact.
#'
#' If you are unfamiliar with CSS, please see the
#' \href{https://github.com/yihui/xaringan/wiki}{xaringan wiki on Github}
#' providing CSS slide modification examples.
#' @param css A vector of CSS file paths. Two default CSS files
#' (\file{default.css} and \file{default-fonts.css}) are provided in this
#' package, which was borrowed from \url{https://remarkjs.com}. If the
#' character vector \code{css} contains a value that does not end with
#' \code{.css}, it is supposed to be a built-in CSS file in this package,
#' e.g., for \code{css = c('default', 'extra.css')}), it means
#' \code{default.css} in this package and a user-provided \code{extra.css}. To
#' find out all built-in CSS files, use \code{xaringan:::list_css()}. With
#' \pkg{rmarkdown} >= 2.8, Sass files (filenames ending with \file{.scss} or
#' \file{.sass}) can also be used, and they will be processed by the
#' \pkg{sass} package, which needs to be installed.
#' @param self_contained Whether to produce a self-contained HTML file by
#' embedding all external resources into the HTML file. See the \sQuote{Note}
#' section below.
#' @param seal Whether to generate a title slide automatically using the YAML
#' metadata of the R Markdown document (if \code{FALSE}, you should write the
#' title slide by yourself).
#' @param yolo Whether to insert the
#' \href{https://kbroman.wordpress.com/2014/08/28/the-mustache-photo/}{Mustache
#' Karl (TM)} randomly in the slides. \code{TRUE} means insert his picture on
#' one slide, and if you want him to be on multiple slides, set \code{yolo} to
#' a positive integer or a percentage (e.g. 0.3 means 30\% of your slides will
#' be the Mustache Karl). Alternatively, \code{yolo} can also be a list of the
#' form \code{list(times = n, img = path)}: \code{n} is the number of times to
#' show an image, and \code{path} is the path to an image (by default, it is
#' Karl).
#' @param chakra A path to the remark.js library (can be either local or
#' remote). Please note that if you use the default remote latest version of
#' remark.js, your slides will not work when you do not have Internet access.
#' They might also be broken after a newer version of remark.js is released.
#' If these issues concern you, you should download remark.js locally (e.g.,
#' via \code{\link{summon_remark}()}), and use the local version instead.
#' @param nature (Nature transformation) A list of configurations to be passed
#' to \code{remark.create()}, e.g. \code{list(ratio = '16:9', navigation =
#' list(click = TRUE))}; see
#' \url{https://github.com/gnab/remark/wiki/Configuration}. Besides the
#' options provided by remark.js, you can also set \code{autoplay} to a number
#' (the number of milliseconds) so the slides will be played every
#' \code{autoplay} milliseconds; alternatively, \code{autoplay} can be a list
#' of the form \code{list(interval = N, loop = TRUE)}, so the slides will go
#' to the next page every \code{N} milliseconds, and optionally go back to the
#' first page to restart the play when \code{loop = TRUE}. You can also set
#' \code{countdown} to a number (the number of milliseconds) to include a
#' countdown timer on each slide. If using \code{autoplay}, you can optionally
#' set \code{countdown} to \code{TRUE} to include a countdown equal to
#' \code{autoplay}. To alter the set of classes applied to the title slide,
#' you can optionally set \code{titleSlideClass} to a vector of classes; the
#' default is \code{c("center", "middle", "inverse")}.
#' @param anchor_sections,... For \code{tsukuyomi()}, arguments passed to
#' \code{moon_reader()}; for \code{moon_reader()}, arguments passed to
#' \code{rmarkdown::\link{html_document}()}.
#' @note Do not stare at Karl's picture for too long after you turn on the
#' \code{yolo} mode. I believe he has Sharingan.
#'
#' For the option \code{self_contained = TRUE}, it encodes images as base64
#' data in the HTML output file. The image path should not contain the string
#' \code{")"} when the image is written with the syntax \verb{} or
#' \verb{background-image: url(PATH)}, and should not contain the string
#' \code{"/>"} when it is written with the syntax \verb{<img src="PATH" />}.
#' Rendering slides in the self-contained mode can be time-consuming when you
#' have remote resources (such as images or JS libraries) in your slides
#' because these resources need to be downloaded first. We strongly recommend
#' that you download remark.js (via \code{\link{summon_remark}()}) and use a
#' local copy instead of the default \code{chakra} argument when
#' \code{self_contained = TRUE}, so remark.js does not need to be downloaded
#' each time you compile your slides.
#'
#' When the slides are previewed via \code{xaringan::\link{inf_mr}()},
#' \code{self_contained} will be temporarily changed to \code{FALSE} even if
#' the author of the slides set it to \code{TRUE}. This will make it faster to
#' preview slides locally (by avoiding downloading remote resources explicitly
#' and base64 encoding them). You can always click the Knit button in RStudio
#' or call \code{rmarkdown::render()} to render the slides in the
#' self-contained mode (these approaches will respect the
#' \code{self_contained} setting).
#'
#' Each page has its own countdown timer (when the option \code{countdown} is
#' set in \code{nature}), and the timer is (re)initialized whenever you
#' navigate to a new page. If you need a global timer, you can use the
#' presenter's mode (press \kbd{P}).
#' @references \url{https://naruto.fandom.com/wiki/Tsukuyomi}
#' @importFrom htmltools tagList tags htmlEscape HTML
#' @export
#' @examples
#' # rmarkdown::render('foo.Rmd', 'xaringan::moon_reader')
moon_reader = function(
css = c('default', 'default-fonts'), self_contained = FALSE, seal = TRUE, yolo = FALSE,
chakra = 'https://remarkjs.com/downloads/remark-latest.min.js', nature = list(),
anchor_sections = FALSE, ...
) {
theme = grep('[.](?:sa|sc|c)ss$', css, value = TRUE, invert = TRUE)
deps = if (length(theme)) {
css = setdiff(css, theme)
check_builtin_css(theme)
list(css_deps(theme))
}
tmp_js = tempfile('xaringan', fileext = '.js') # write JS config to this file
tmp_md = tempfile('xaringan', fileext = '.md') # store md content here (bypass Pandoc)
options(xaringan.page_number.offset = if (seal) 0L else -1L)
if (self_contained && isTRUE(getOption('xaringan.inf_mr.running'))) {
if (interactive()) xfun::do_once({
message(
'You are currently using xaringan::inf_mr() to preview your slides, and ',
'you have turned on the self_contained option in xaringan::moon_reader. ',
'To make it faster for you to preview slides, I have temporarily turned ',
'this option off. If you need self-contained slides at the end, you may ',
'click the Knit button in RStudio, or call rmarkdown::render() to render ',
'this document.'
)
readline('Press Enter to continue...')
}, 'xaringan.self_contained.message')
self_contained = FALSE
}
if (is.numeric(autoplay <- nature[['autoplay']])) {
autoplay = list(interval = autoplay, loop = FALSE)
}
play_js = if (is.numeric(intv <- autoplay$interval) && intv > 0) sprintf(
'setInterval(function() {slideshow.gotoNextSlide();%s}, %d);',
if (!isTRUE(autoplay$loop)) '' else
' if (slideshow.getCurrentSlideIndex() == slideshow.getSlideCount() - 1) slideshow.gotoFirstSlide();',
intv
)
if (isTRUE(countdown <- nature[['countdown']])) countdown = autoplay
countdown_js = if (is.numeric(countdown) && countdown > 0) sprintf(
'(%s)(%d);', pkg_file('js/countdown.js'), countdown
)
hl_pre_js = if (isTRUE(nature$highlightLines))
pkg_file('js/highlight-pre-parent.js')
if (is.null(title_cls <- nature[['titleSlideClass']]))
title_cls = c('center', 'middle', 'inverse')
title_cls = paste(c(title_cls, 'title-slide'), collapse = ', ')
before = nature[['beforeInit']]
for (i in c('countdown', 'autoplay', 'beforeInit', 'titleSlideClass')) nature[[i]] = NULL
write_utf8(as.character(tagList(
tags$style(`data-target` = 'print-only', '@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}'),
tags$script(src = chakra),
if (is.character(before)) if (self_contained) {
tags$script(HTML(file_content(before)))
} else {
lapply(before, function(s) tags$script(src = s))
},
tags$script(HTML(paste(c(sprintf(
'var slideshow = remark.create(%s);', if (length(nature)) xfun::tojson(nature) else ''
), pkg_file(sprintf('js/%s.js', c(
'show-widgets', 'print-css', 'after', 'script-tags', 'target-blank'
))),
play_js, countdown_js, hl_pre_js), collapse = '\n')))
)), tmp_js)
html_document2 = function(
..., includes = list(), mathjax = 'default', pandoc_args = NULL
) {
if (length(includes) == 0) includes = list()
includes$before_body = c(includes$before_body, tmp_md)
includes$after_body = c(tmp_js, includes$after_body)
if (identical(mathjax, 'local'))
stop("mathjax = 'local' does not work for moon_reader()")
if (!is.null(mathjax)) {
if (identical(mathjax, 'default')) {
mathjax = 'https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML'
}
pandoc_args = c(pandoc_args, '-V', paste0('mathjax-url=', mathjax))
mathjax = NULL
}
pandoc_args = c(pandoc_args, '-V', paste0('title-slide-class=', title_cls))
# avoid automatic wrapping: https://github.com/yihui/xaringan/issues/345
if (!length(grep('--wrap', pandoc_args)))
pandoc_args = c('--wrap', 'preserve', pandoc_args)
rmarkdown::html_document(
..., includes = includes, mathjax = mathjax, pandoc_args = pandoc_args
)
}
highlight_hooks = NULL
if (isTRUE(nature$highlightLines)) {
hooks = knitr::hooks_markdown()[c('source', 'output')]
highlight_hooks = list(
source = function(x, options) {
hook = hooks[['source']]
res = hook(x, options)
highlight_code(res)
},
output = function(x, options) {
hook = hooks[['output']]
res = highlight_output(x, options)
hook(res, options)
}
)
}
opts = list()
rmarkdown::output_format(
rmarkdown::knitr_options(knit_hooks = highlight_hooks),
NULL, clean_supporting = self_contained,
pre_knit = function(input, ...) {
opts <<- options(
htmltools.preserve.raw = FALSE, # don't use Pandoc raw blocks ```{=} (#293)
knitr.sql.html_div = FALSE # do not add <div> to knitr's sql output (#307)
)
},
pre_processor = function(
metadata, input_file, runtime, knit_meta, files_dir, output_dir
) {
res = split_yaml_body(input_file)
write_utf8(res$yaml, input_file)
res$body = protect_math(res$body)
if (self_contained) {
clean_env_images()
res$body = encode_images(res$body)
cat(sprintf(
"<script>(%s)(%s, '%s');</script>", pkg_file('js/data-uri.js'),
xfun::tojson(as.list(env_images, all.names = TRUE)), url_token
), file = tmp_js, append = TRUE)
}
content = htmlEscape(yolofy(res$body, yolo))
Encoding(content) = 'UTF-8'
write_utf8(content, tmp_md)
c(
if (seal) c('--variable', 'title-slide=true'),
if (!identical(body, res$body)) c('--variable', 'math=true')
)
},
on_exit = function() {
unlink(c(tmp_md, tmp_js))
options(opts)
},
base_format = html_document2(
css = css, self_contained = self_contained, theme = NULL, highlight = NULL,
extra_dependencies = deps, template = pkg_resource('default.html'),
anchor_sections = anchor_sections, ...
)
)
}
#' @export
#' @rdname moon_reader
tsukuyomi = function(...) moon_reader(...)
#' Serve and live reload slides
#'
#' Use the \pkg{servr} package to serve and reload slides on change.
#' \code{inf_mr()} and \code{mugen_tsukuyomi()} are aliases of
#' \code{infinite_moon_reader()}.
#'
#' The Rmd document is compiled continuously to trap the world in the Infinite
#' Tsukuyomi. The genjutsu is cast from the directory specified by
#' \code{cast_from}, and the Rinne Sharingan will be reflected off of the
#' \code{moon}. Use \code{servr::daemon_stop()} to perform a genjutsu Kai and
#' break the spell.
#' @param moon The input Rmd file path (if missing and in RStudio, the current
#' active document is used).
#' @param cast_from The root directory of the server.
#' @param ... Passed to \code{rmarkdown::\link[rmarkdown]{render}()}.
#' @references \url{https://naruto.fandom.com/wiki/Infinite_Tsukuyomi}
#' @note This function is not really tied to the output format
#' \code{\link{moon_reader}()}. You can use it to serve any single-HTML-file R
#' Markdown output.
#' @seealso \code{servr::\link{httw}}
#' @export
#' @rdname inf_mr
infinite_moon_reader = function(moon, cast_from = '.', ...) {
# when this function is called via the RStudio addin, use the dir of the
# current active document
if (missing(moon) && requireNamespace('rstudioapi', quietly = TRUE)) {
moon = rstudioapi::getSourceEditorContext()[['path']]
if (is.null(moon)) stop('Cannot find an open document in the RStudio editor')
if (moon == '') stop('Please save the current document')
if (!grepl('[.]R?md$', moon, ignore.case = TRUE)) stop(
'The current active document must be an R Markdown document. I saw "',
basename(moon), '".'
)
}
moon = normalize_path(moon)
dots = list(...)
dots$envir = parent.frame()
dots$input = moon
rebuild = function() {
# set an option so we know that the inf moon reader is running
opts = options(xaringan.inf_mr.running = TRUE)
on.exit(options(opts), add = TRUE)
do.call(rmarkdown::render, dots)
}
html = NULL
# rebuild if moon or any dependencies (CSS/JS/images) have been updated
build = local({
# if Rmd is inside a package, listen to changes under the inst/ dir,
# otherwise watch files under the dir of the moon
d = if (p <- is_package()) 'inst' else dirname(moon)
files = if (getOption('xaringan.inf_mr.aggressive', TRUE)) function() {
list.files(
d, '[.](css|js|png|gif|jpeg|Rmd)$', full.names = TRUE, recursive = TRUE
)
} else function() moon
mtime = function() {
fs = files()
setNames(file.info(fs)[, 'mtime'], fs)
}
html <<- normalize_path(rebuild()) # render Rmd initially
l = max(m <- mtime()) # record the latest timestamp of files
r = servr:::is_rstudio(); info = if (r) slide_context()
function(message) {
m2 = mtime(); u = !any(m2 > l)
# when running inside RStudio and only Rmd is possibly changed
if (u) {
if (!r || missing(message)) return(FALSE)
ctx = rstudioapi::getSourceEditorContext()
if (identical(normalize_path(as.character(ctx[['path']])), moon)) {
if (is.character(message)) message = jsonlite::fromJSON(message)
if (isTRUE(message[['focused']])) {
# auto-navigate to the slide source corresponding to current HTML
# page only when the slides are on focus
slide_navigate(ctx, message)
} else {
# navigate to HTML page and update it incrementally if necessary
info2 = slide_context(ctx)
# incremental update only if the total number of pages (N) matches
if (!is.null(info2) && identical(message$N, info2$N)) {
on.exit(info <<- info2, add = TRUE)
return(list(page = info2$n, markdown = if (
identical(info$c, info2$c) || is.null(info2$c) || !identical(info$n, info2$n)
) FALSE else process_slide(info2$c)))
}
}
}
return(FALSE)
}
# is any Rmd updated?
u2 = !u && any(m2[grep('[.]Rmd$', names(m2))] > l)
l <<- max(m2)
# moon or dependencies have been updated, recompile and reload in browser
if (p || u2) {
rebuild(); if (r) info <<- slide_context()
}
l <<- max(m <<- mtime())
TRUE
}
})
d = normalize_path(cast_from)
f = rmarkdown::relative_to(d, html)
# see if the html output file is under the dir cast_from
if (f == html) {
d = dirname(html)
f = basename(html)
warning(
"Cannot use '", cast_from, "' as the root directory of the server because ",
"the HTML output is not under this directory. Using '", d, "' instead."
)
}
servr:::dynamic_site(
d, initpath = f, build = build, ws_handler = pkg_resource('js', 'ws-handler.js')
)
}
#' @export
#' @rdname inf_mr
inf_mr = infinite_moon_reader
#' @export
#' @rdname inf_mr
mugen_tsukuyomi = infinite_moon_reader
#' Convert HTML presentations to PDF via DeckTape
#'
#' This function can use either the \command{decktape} command or the hosted
#' docker image of the \pkg{decktape} library to convert HTML slides to PDF
#' (including slides produced by \pkg{xaringan}).
#' @param file The path to the HTML presentation file. When \code{docker =
#' FALSE}, this path could be a URL to online slides.
#' @param output The desired output path of the PDF file.
#' @param args Command-line arguments to be passed to \code{decktape}.
#' @param docker Whether to use Docker (\code{TRUE}) or use the
#' \command{decktape} command directly (\code{FALSE}). By default, if
#' \pkg{decktape} has been installed in your system and can be found via
#' \code{Sys.which('decktape')}, it will be uesd directly.
#' @param version The \pkg{decktape} version when you use Docker.
#' @param open Whether to open the resulting PDF with your system PDF viewer.
#' @note For some operating systems you may need to
#' \href{https://stackoverflow.com/questions/48957195}{add yourself to the
#' \command{docker} group} and restart your machine if you use DeckTape via
#' Docker. By default, the latest version of the \pkg{decktape} Docker image
#' is used. In case of errors, you may want to try older versions (e.g.,
#' \code{version = '2.8.0'}).
#' @references DeckTape: \url{https://github.com/astefanutti/decktape}. Docker:
#' \url{https://www.docker.com}.
#' @return The output file path (invisibly).
#' @export
#' @examplesIf interactive()
#' xaringan::decktape('https://slides.yihui.org/xaringan', 'xaringan.pdf', docker = FALSE)
decktape = function(
file, output, args = '--chrome-arg=--allow-file-access-from-files',
docker = Sys.which('decktape') == '', version = '', open = FALSE
) {
args = shQuote(c(args, file, output))
res = if (docker) system2('docker', c(
'run', '--rm', '-t', '-v', '`pwd`:/slides', '-v', '$HOME:$HOME',
paste0('astefanutti/decktape', if (version != '') ':', version), args
)) else system2('decktape', args)
if (res != 0) stop('Failed to convert ', file, ' to PDF')
if (open) open_file(output)
invisible(output)
}
| /scratch/gouwar.j/cran-all/cranData/xaringan/R/render.R |
#' @import utils
#' @import stats
#' @importFrom xfun read_utf8 write_utf8 normalize_path prose_index protect_math
pkg_resource = function(...) system.file(
'rmarkdown', 'templates', 'xaringan', 'resources', ..., package = 'xaringan',
mustWork = TRUE
)
css_deps = function(theme) {
htmltools::htmlDependency(
'remark-css', '0.0.1', pkg_resource(), stylesheet = paste0(theme, '.css'),
all_files = FALSE
)
}
list_css = function() {
css = list.files(pkg_resource(), '[.]css$', full.names = TRUE)
setNames(css, gsub('.css$', '', basename(css)))
}
check_builtin_css = function(theme) {
valid = names(list_css())
if (length(invalid <- setdiff(theme, valid)) == 0) return()
invalid = invalid[1]
maybe = sort(agrep(invalid, valid, value = TRUE))[1]
hint = if (is.na(maybe)) '' else paste0('; did you mean "', maybe, '"?')
stop(
'"', invalid, '" is not a valid xaringan theme', if (hint != "") hint else ".",
" Use `xaringan:::list_css()` to view all built-in themes.", call. = FALSE
)
}
split_yaml_body = function(file) {
x = readLines(file, encoding = 'UTF-8')
i = grep('^---\\s*$', x)
n = length(x)
if (length(i) < 2) {
list(yaml = character(), body = x)
} else {
list(yaml = x[i[1]:i[2]], body = if (i[2] == n) character() else x[(i[2] + 1):n])
}
}
karl = 'https://github.com/yihui/xaringan/releases/download/v0.0.2/karl-moustache.jpg'
yolo = function(img = karl, ...) {
knitr::include_graphics(img, ...)
}
yolofy = function(x, config) {
if (!is.list(config)) config = list(times = config, img = karl)
n = as.numeric(config$times); img = config$img
if (!is.character(img)) img = karl
if (n <= 0) return(x)
i = grep('^---$', x)
b = sprintf('background-image: url(%s)', img)
if (length(i) == 0) return(c(x, '---', b))
if (n < 1) n = ceiling(n * length(i))
n = min(n, length(i))
j = sample2(i, n)
# randomly add Karl above or below a slide
x[j] = paste(c('---', b, '---'), collapse = '\n')
x
}
# sample() without surprise
sample2 = function(x, size, ...) {
if (length(x) == 1) {
rep(x, size) # should consider replace = FALSE in theory
} else sample(x, size, ...)
}
#' Summon remark.js to your local disk
#'
#' Download a version of the remark.js script to your local disk, so you can
#' render slides offline. You need to change the \code{chakra} argument of
#' \code{\link{moon_reader}()} after downloading remark.js.
#' @param version The version of remark.js (e.g. \code{latest}, \code{0.13}, or
#' \code{0.14.1}).
#' @param to The destination directory.
#' @export
summon_remark = function(version = 'latest', to = 'libs/') {
name = sprintf('remark-%s.min.js', version)
if (!utils::file_test('-d', to)) dir.create(to, recursive = TRUE)
download.file(
paste0('https://remarkjs.com/downloads/', name),
file.path(to, name)
)
}
# replace {{code}} with *code so that this line can be highlighted in remark.js;
# this also works with multiple lines
highlight_code = function(x) {
x = paste0('\n', x) # prepend \n and remove it later
r = '(\n)([ \t]*)\\{\\{(.+?)\\}\\}(?=(\n|$))'
m = gregexpr(r, x, perl = TRUE)
regmatches(x, m) = lapply(regmatches(x, m), function(z) {
z = gsub(r, '\\1\\2\\3', z, perl = TRUE) # remove {{ and }}
z = gsub('\n', '\n*', z) # add * after every \n
z
})
x = gsub('^\n', '', x)
# adds support for `#<<` line highlight marker at line end in code segments
# catch `#<<` at end of the line but ignores lines that start with `*` since
# they came from above
x = gsub('^\\s?([^*].+?)\\s*#<<\\s*$', '*\\1', split_lines(x))
paste(x, collapse = '\n')
}
highlight_output = function(x, options) {
if (is.null(i <- options$highlight.output) || isFALSE(i)) return(x)
x = split_lines(x)
x[i] = paste0('*', x[i])
paste(x, collapse = '\n')
}
# make sure blank lines and trailing \n are not removed by strsplit()
split_lines = function(x) {
unlist(strsplit(paste0(x, '\n'), '\n'))
}
file_content = function(file) {
paste(unlist(lapply(file, read_utf8)), collapse = '\n')
}
pkg_file = function(file) file_content(pkg_resource(file))
open_file = function(path){
if (xfun::is_windows()) {
shell.exec(path)
} else {
system2(if (xfun::is_macos()) 'open' else 'xdg-open', shQuote(path))
}
}
# does the current dir look like an R package dir?
is_package = function() {
all(c(file.exists(c('DESCRIPTION', 'NAMESPACE')), dir.exists(c('R', 'inst'))))
}
# obtain the context of Rmd for xaringan slides
slide_context = function(ctx = rstudioapi::getSourceEditorContext()) {
x = ctx$contents
if (length(x) < 3 || length(s <- which(x == '---')) < 2 || s[1] != 1) return()
if (length(grep(' xaringan::.+', x[1:s[2]])) == 0) return()
l = ctx$selection[[1]]$range$end[1] # line number of cursor
i = prose_index(x, warn = FALSE); x2 = x; if (length(i)) x2[-i] = ''
s = grep('^---?$', x2) # line numbers of slide separators; first two are YAML
# remove hidden slides from the source
k = unlist(lapply(grep(reg_hidden, x2), function(i) {
i1 = tail(s[s < i], 1); if (length(i1) == 0) i1 = 1
i2 = head(s[s > i], 1); if (length(i2) == 0) i2 = length(x)
(i1 + 1):i2
}))
if (length(k)) {
x[k] = ''; x2[k] = ''; s = grep('^---?$', x2)
}
i = which(x2 == '---')
n = max(sum(s <= l), 1)
i1 = tail(i[i <= l], 1); if (length(i1) == 0) i1 = 1
i2 = s[n + 1]; if (is.na(i2)) i2 = length(x)
txt = x[i1:i2]; i = grep('^---?$', txt)
if (length(i)) txt = txt[-i]
o = getOption('xaringan.page_number.offset', 0L)
# total # of pages; current page #; Markdown content of current page
list(
N = as.integer(length(s) + o), n = n + o, c = if (i1 > 1) txt
)
}
reg_hidden = '^(layout|exclude): true\\s*$'
slide_navigate = function(ctx = rstudioapi::getSourceEditorContext(), message) {
if (!is.list(message) || !is.numeric(p <- message$n)) return()
sel = ctx$selection[[1]]
if (sel$text != '') return() # when user has selected some text, don't navigate
l = sel$range$end[1]; x = ctx$contents
i = prose_index(x, warn = FALSE); x2 = x; if (length(i)) x2[-i] = ''
s = grep('^---?$', x2); o = getOption('xaringan.page_number.offset', 0L)
k = unlist(lapply(grep(reg_hidden, x2), function(i) sum(s < i)))
k = unique(k[k > 0])
if (length(k)) s = s[-k]
if (length(s) + o != message$N) return()
n = max(sum(s <= l), 1); p = p - o
# don't move cursor if already on the current page
if (n != p && p <= length(s))
rstudioapi::setCursorPosition(rstudioapi::document_position(s[p] + 1, 1))
}
flatten_chunk = function(x) {
if (length(i <- grep(knitr::all_patterns$md$chunk.begin, x)) == 0) return(x)
k = grepl('\\W(echo|include)\\s*=\\s*FALSE\\W', x[i])
x[i][!k] = gsub('\\{.+', '', x[i][!k])
x[i][k] = gsub('\\{.+', '.hidden', x[i][k])
x
}
process_slide = function(x) {
x = protect_math(flatten_chunk(x))
paste(x, collapse = '\n')
}
# store the base64 data of images (indexed by image paths)
env_images = new.env(parent = emptyenv())
clean_env_images = function() {
rm(list = ls(env_images, all.names = TRUE), envir = env_images)
}
url_token = 'data:image/png;base64,#'
# find images in Markdown, encode them in base64, and store the data in JSON
# (the data will be used when post-processing remark.js slides in browser)
encode_images = function(x) {
# only process prose lines and not code blocks
if (length(p <- prose_index(x)) == 0) return(x)
xp = x[p]
# opening and closing tags of images and other media
rs = matrix(c(
'!\\[.*?\\]\\(', '\\)',
'<img .*?src\\s*=\\s*"', '".*?/>',
rbind(sprintf('<%s .*?src\\s*=\\s*"', c('audio', 'video', 'source')), '".*?>'),
'^background-image: url\\("?', '"?\\)'
), 2)
rs = paste0('(?<!`)(', rs[1, ], ')(.*?)(', rs[2, ], ')(?!`)')
for (r in rs) xp = encode_reg(r, xp)
x[p] = xp
x
}
# given a regex for images, base64 encode these images
encode_reg = function(r, x) {
m = gregexpr(r, x, perl = TRUE)
regmatches(x, m) = lapply(regmatches(x, m), function(imgs) {
if ((n <- length(imgs)) == 0) return(imgs)
x1 = gsub(r, '\\1', imgs, perl = TRUE)
x2 = gsub(r, '\\2', imgs, perl = TRUE)
x3 = gsub(r, '\\3', imgs, perl = TRUE)
for (i in seq_len(n)) {
f = x2[i]
if (f == '') next # src shouldn't be empty
# don't re-encode if the file has been encoded previously
if (!(ok <- !is.null(env_images[[f]]))) {
b = encode_file(f)
if (b == f) next
env_images[[f]] = b
ok = TRUE
}
# dirty hack: hide paths after a base64 string and we'll replace it
# will the actual base64 data after the slides are rendered in browser
if (ok) x2[i] = paste0(url_token, f)
}
paste0(x1, x2, x3)
})
x
}
encode_file = function(x) {
if (grepl('^data:[^/]+/[^;]+;base64,', x)) return(x) # already encoded
tf = x
if (grepl('^https?://.+', x)) {
tf = tempfile(fileext = xfun::url_filename(x))
xfun::download_file(x, tf, mode = 'wb', quiet = TRUE)
on.exit(unlink(tf), add = TRUE)
}
if (!file.exists(tf)) {
warning('Failed to encode the file ', x)
return(x)
}
xfun::base64_uri(tf)
}
| /scratch/gouwar.j/cran-all/cranData/xaringan/R/utils.R |
---
title: "FC Theme"
subtitle: "powered by xaringan"
author: "Yue Jiang"
date: "Last updated: `r Sys.Date()`"
output:
xaringan::moon_reader:
css: ["default", "fc", "fc-fonts"]
lib_dir: libs
nature:
highlightStyle: github
countIncrementalSlides: false
highlightLines: true
---
```{r setup, include = FALSE}
options(htmltools.dir.version = FALSE)
```
# Headers and fonts
# h1
## h2
### h3
.large[large content font size] `.large[large content font size]`
regular content font size
.small[small content font size] `.small[small content font size]`
---
class: center, middle
# Various two-column splits
---
# 30-70 split columns
.pull-left-30[
## left column
### `.pull-left-30`
### I am 30%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
.pull-right-70[
## right column
### `.pull-right-70`
### I am 70%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
I am a new line, not those two columns anymore. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
---
# 40-60 split columns
.pull-left-40[
## left column
### `.pull-left-40`
### I am 40%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
.pull-right-60[
## right column
### `.pull-right-60`
### I am 60%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
I am a new line, not those two columns anymore. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
---
# 50-50 split columns
This is not much different than the default `.pull-left` and `.pull-right`. Only 1% less white space in the middle.
.pull-left-50[
## left column
### `.pull-left-50`
### I am 50%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
.pull-right-50[
## right column
### `.pull-right-50`
### I am 50%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
I am a new line, not those two columns anymore. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
---
# 60-40 split columns
.pull-left-60[
## left column
### `.pull-left-60`
### I am 60%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
.pull-right-40[
## right column
### `.pull-right-40`
### I am 40%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
I am a new line, not those two columns anymore. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
---
# 70-30 split columns
.pull-left-70[
## left column
### `.pull-left-70`
### I am 70%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
.pull-right-30[
## right column
### `.pull-right-30`
### I am 30%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
]
I am a new line, not those two columns anymore. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
---
class: inverse
# Inverse `class: inverse`
# h1
## h2
### h3
.large[large content font size] `.large[large content font size]`
regular content font size
.small[small content font size] `.small[small content font size]`
---
# Code and math
- In line code `I will mess with time`
- In line math $E=mc^2$
- Display math
$$E=mc^2$$
- Code chunk (highlight with the `#<<` as line comment)
```{r, eval=FALSE}
for (i in 1:3) {
print("I will mess with time") #<<
}
```
---
class: inverse
# Code and math, inverse
- In line code `I will mess with time`
- In line math $E=mc^2$
- Display math
$$E=mc^2$$
- Code chunk (highlight with the `#<<` as line comment)
```{r, eval=FALSE}
for (i in 1:3) {
print("I will mess with time") #<<
}
```
| /scratch/gouwar.j/cran-all/cranData/xaringan/inst/examples/fc-demo.Rmd |
---
title: "Presentation Ronin"
subtitle: "⚔<br/>with xaringan and a twist of hygge"
author: "Claus Thorn Ekstrøm"
date: "2018/02/16"
output:
xaringan::moon_reader:
css: ["default", "default-fonts", "hygge"]
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
class: center, middle
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
# hygge
### /ˈhʊgə/
A quality of cosiness and comfortable conviviality that engenders a feeling of contentment or well-being (regarded as a defining characteristic of Danish culture)
*‘why not follow the Danish example and bring more hygge into your daily life?’*
---
class: inverse, center, middle
# Template-independent content-classes
To use, say, the large content class wrap your code in `.large[Large text]`.
---
# Modifying text
.pull-left[
## Font sizes
This is normal size ( $\LaTeX$-friendly terms)
.Large[Large]
.large[large]
.small[small]
.footnotesize[footnotesize]
.scriptsize[scriptsize]
.tiny[tiny]
]
.pull-right[
## Text color
.black[black]
.red[red]
.blue[blue]
.green[green],
.yellow[yellow],
.orange[orange],
.purple[purple],
.gray[gray or grey]
You can also use `.bold[]` or `.bolder[]` to emphasize text
This is .bold[bold], this is .bolder[bolder] and this is regular markdown **double-star bold** (visible differences depend on the font)
]
---
## Coloured content boxes
Use `.content-box-blue` (or gray/grey, army, green, purple, red, or yellow) to produce a box with coloured background. Size depends on content.
`.content-box-blue[I feel blue]` yields
.content-box-blue[I feel blue]
Wrap in `.full-width` to expand the width
.full-width[.content-box-red[I feel even more blue]]
If you have content in columns then you get
.pull-left[.full-width[.content-box-yellow[**WARNING** Look out for minons or bananas]]]
.pull-right[.full-width[.content-box-yellow[The box to the left was created using `.pull-left[.full-width[.content-box-yellow[]]]`]]]
---
## Fancy picture includes
.pull-left[
Original:
```{r echo=FALSE, out.width="80%"}
knitr::include_graphics("https://www.worldtravelguide.net/wp-content/uploads/2017/04/Think-Denmark-Copenhagen-587892190-SeanPavonePhoto-copy.jpg")
```
Add `.polaroid`
.polaroid[
```{r echo=FALSE, out.width="80%"}
knitr::include_graphics("https://www.worldtravelguide.net/wp-content/uploads/2017/04/Think-Denmark-Copenhagen-587892190-SeanPavonePhoto-copy.jpg")
```
]
]
.pull-right[
Rotated slightly:
.rotate-right[
```{r echo=FALSE, out.width="80%"}
knitr::include_graphics("https://www.worldtravelguide.net/wp-content/uploads/2017/04/Think-Denmark-Copenhagen-587892190-SeanPavonePhoto-copy.jpg")
```
]
Add `.blur`
.blur[
```{r echo=FALSE, out.width="80%"}
knitr::include_graphics("https://www.worldtravelguide.net/wp-content/uploads/2017/04/Think-Denmark-Copenhagen-587892190-SeanPavonePhoto-copy.jpg")
```
]
]
---
## Stacking fancy picture options
.pull-left[
Add `.opacity`
.opacity[
```{r echo=FALSE, out.width="80%"}
knitr::include_graphics("https://www.worldtravelguide.net/wp-content/uploads/2017/04/Think-Denmark-Copenhagen-587892190-SeanPavonePhoto-copy.jpg")
```
]
Stack `.blur` and `.opacity`
.blur[.opacity[
```{r echo=FALSE, out.width="80%"}
knitr::include_graphics("https://www.worldtravelguide.net/wp-content/uploads/2017/04/Think-Denmark-Copenhagen-587892190-SeanPavonePhoto-copy.jpg")
```
]]
]
.pull-right[
Convert to `.grayscale` (oh ... and rotate just for s'n'g):
.rotate-left[
.grayscale[
```{r echo=FALSE, out.width="80%"}
knitr::include_graphics("https://www.worldtravelguide.net/wp-content/uploads/2017/04/Think-Denmark-Copenhagen-587892190-SeanPavonePhoto-copy.jpg")
```
]]
Add `.shadow`
.shadow[
```{r echo=FALSE, out.width="100%"}
knitr::include_graphics("https://beautifulenvironments.files.wordpress.com/2017/12/twinkly-lights.jpg")
```
]
]
| /scratch/gouwar.j/cran-all/cranData/xaringan/inst/examples/ghoul.Rmd |
---
title: "Karolinska Institutet Theme"
subtitle: "...powered by [xaringan](https://github.com/yihui/xaringan)"
author: "Developed by Alessandro Gasparini"
date: "Last updated: `r Sys.Date()`"
output:
xaringan::moon_reader:
css: ["ki", "ki-fonts"]
---
```{r setup, include = FALSE}
options(htmltools.dir.version = FALSE)
```
# Hello World
Install the **xaringan** package from CRAN:
```{r eval = FALSE, tidy = FALSE}
install.packages("xaringan")
```
--
You are recommended to use the [RStudio IDE](https://www.rstudio.com/products/rstudio/), but you do not have to.
- Create a new R Markdown document from the menu `File -> New File -> R Markdown -> From Template -> Ninja Presentation`;
--
- Click the `Knit` button to compile it;
--
- or use the [RStudio Addin](https://rstudio.github.io/rstudioaddins/)<sup>1</sup> "Infinite Moon Reader".
.footnote[
[1] See [#2](https://github.com/yihui/xaringan/issues/2) if you do not see the template or addin in RStudio.
]
---
# Extra colours
The `ki` theme includes extra colours and font sizes.
Colours: .plum[`.plum[]`], .dark-plum[`.dark-plum[]`], .grey[`.grey[]`], .light-grey[`.light-grey[]`], .white[`.white[]`], .black[`.black[]`], .blackish[`.blackish[]`], .orange[`.orange[]`], .light-orange[`.light-orange[]`], .light-blue[`.light-blue[]`], .main[`.main[]`], .accent[`.accent[]`], .text[`.text[]`], .text-inverse[`.text-inverse[]`].
The colours of the theme can be easily customised - see `ki.css`.
---
# Extra font sizes:
The `ki` theme includes extra colours and font sizes.
Font-sizes: .tiny[(.)tiny[]], .scriptsize[(.)scriptsize[]], .footnotesize[(.)footnotesize[]], .small[(.)small[]], .normalsize[(.)normalsize[]], .large[(.)large[]], .Large[(.)Large[]], .LARGE[(.)LARGE[]], .huge[(.)huge[]], .Huge[(.)Huge[]], .references[(.)references[]].
---
# Lists
1. One
2. Two
3. Three
* A
* B
* C
---
# R output
```{r cars}
s <- summary(cars)
s
```
---
# Plot
```{r pressure, echo = FALSE}
plot(pressure)
```
---
# Disclaimer
The Karolinska Institutet logo is used for dissemination purposes only.
Please read the webpage with the visual identity guidelines before using this template: https://staff.ki.se/brand-platform-and-graphic-profile
| /scratch/gouwar.j/cran-all/cranData/xaringan/inst/examples/ki-demo.Rmd |
---
title: "My presentation"
author: "Lucy D'Agostino McGowan"
date: "2018/02/16"
output:
xaringan::moon_reader:
css: ["default", "lucy", "lucy-fonts"]
lib_dir: libs
nature:
highlightStyle: agate
highlightLines: true
countIncrementalSlides: false
---
layout: true
<div class = "footer">MY CONFERENCE 2018</div>
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
# Overview
1. First thing
2. Second thing
3. Third thing
---
class: inverse, left, bottom
# First thing
---
# Some code
```{r, fig.height = 4}
library(ggplot2)
ggplot(mtcars, aes(am)) +
geom_bar(fill = "#92d050")
```
---
# A list
* this is one thing
* this is another, this next part is **important**
* this is a bit of `inline code`
* this is a [link](www.lucymcgowan.com)
| /scratch/gouwar.j/cran-all/cranData/xaringan/inst/examples/lucy-demo.Rmd |
---
title: "UoL Theme"
subtitle: "...powered by xaringan"
author: "Alessandro Gasparini"
date: "Last updated: `r Sys.Date()`"
output:
xaringan::moon_reader:
css: ["uol", "uol-fonts"]
lib_dir: libs
nature:
highlightStyle: github
countIncrementalSlides: false
---
```{r setup, include = FALSE}
options(htmltools.dir.version = FALSE)
```
# Hello World
Install the **xaringan** package from [Github](https://github.com/yihui/xaringan):
```{r eval=FALSE, tidy=FALSE}
remotes::install_github("yihui/xaringan")
```
--
You are recommended to use the [RStudio IDE](https://www.rstudio.com/products/rstudio/), but you do not have to.
- Create a new R Markdown document from the menu `File -> New File -> R Markdown -> From Template -> Ninja Presentation`;<sup>1</sup>
--
- Click the `Knit` button to compile it;
--
- or use the [RStudio Addin](https://rstudio.github.io/rstudioaddins/)<sup>2</sup> "Infinite Moon Reader" to live preview the slides (every time you update and save the Rmd document, the slides will be automatically reloaded in RStudio Viewer.
.footnote[
[1] 中文用户请看[这份教程](https://slides.yihui.org/xaringan/zh-CN.html)
[2] See [#2](https://github.com/yihui/xaringan/issues/2) if you do not see the template or addin in RStudio.
]
---
# Extra colours
The `uol` theme includes extra colours and font sizes.
Colours: .corporate-red[`.corporate-red[]`], .corporate-grey[`.corporate-grey[]`], .white[`.white[]`], .vibrant-red[`.vibrant-red[]`], .orange[`.orange[]`], .warm-yellow[`.warm-yellow[]`], .vc-green[`.vc-green[]`], .dark-green[`.dark-green[]`], .mid-green[`.mid-green[]`], .acid-green[`.acid-green[]`], .dark-blue[`dark-blue[]`], .mid-blue[`.mid-blue[]`], .light-blue[`.light-blue[]`], .mauve-blue[`.mauve-blue[]`], .dark-warm-grey[`.dark-warm-grey[]`], .mid-warm-grey[`.mid-warm-grey[]`], .light-warm-grey[`.light-warm-grey[]`], .black[`.black[]`], .mid-cool-grey[`.mid-cool-grey[]`], .light-cool-grey[`.light-cool-grey[]`], .digi-gold[`.digi-gold[]`], .light-digi-gold[`.light-digi-gold[]`], .magenta[`.magenta[]`], .bright-yellow[`.bright-yellow[]`], .cyan[`.cyan[]`], .royal-blue[`.royal-blue[]`], .metallic-gold[`.metallic-gold[]`], .metallic-gold-70p[`.metallic-gold-70p[]`], .metallic-silver[`.metallic-silver[]`], .metallic-silver-70p[`.metallic-silver-70p[]`], .main[`.main[]`], .accent[`.accent[]`], .text[`.text[]`], .text-inverse[`.text-inverse[]`].
The colours of the theme can be easily customised - see `uol.css`.
---
# Extra font sizes:
The `uol` theme includes extra colours and font sizes.
Font-sizes: .tiny[`.tiny[]`], .scriptsize[`.scriptsize[]`], .footnotesize[`.footnotesize[]`], .small[`.small[]`], .normalsize[`.normalsize[]`], .large[`.large[]`], .Large[`.Large[]`], .LARGE[`.LARGE[]`], .huge[`.huge[]`], .Huge[`.Huge[]`], .references[`.references[]`].
---
# Lists
1. One
2. Two
3. Three
* A
* B
* C
---
# R output
```{r cars}
summary(cars)
```
---
# Plot
```{r pressure, echo = FALSE}
plot(pressure)
```
---
# Disclaimer
The university logo is used for dissemination purposes only - please read the webpage with the visual identity guidelines: https://www2.le.ac.uk/offices/external/marcomms/creative/identity
The logo is still property of the University of Leicester (https://le.ac.uk/).
| /scratch/gouwar.j/cran-all/cranData/xaringan/inst/examples/uol-demo.Rmd |
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg)
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
???
Image credit: [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Sharingan_triple.svg)
---
class: center, middle
# xaringan
### /ʃaː.'riŋ.ɡan/
---
class: inverse, center, middle
# Get Started
---
# Hello World
Install the **xaringan** package from [Github](https://github.com/yihui/xaringan):
```{r eval=FALSE, tidy=FALSE}
remotes::install_github("yihui/xaringan")
```
--
You are recommended to use the [RStudio IDE](https://www.rstudio.com/products/rstudio/), but you do not have to.
- Create a new R Markdown document from the menu `File -> New File -> R Markdown -> From Template -> Ninja Presentation`;<sup>1</sup>
--
- Click the `Knit` button to compile it;
--
- or use the [RStudio Addin](https://rstudio.github.io/rstudioaddins/)<sup>2</sup> "Infinite Moon Reader" to live preview the slides (every time you update and save the Rmd document, the slides will be automatically reloaded in RStudio Viewer.
.footnote[
[1] 中文用户请看[这份教程](https://slides.yihui.org/xaringan/zh-CN.html)
[2] See [#2](https://github.com/yihui/xaringan/issues/2) if you do not see the template or addin in RStudio.
]
---
background-image: url(`r xaringan:::karl`)
background-position: 50% 50%
class: center, bottom, inverse
# You only live once!
---
# Hello Ninja
As a presentation ninja, you certainly should not be satisfied by the "Hello World" example. You need to understand more about two things:
1. The [remark.js](https://remarkjs.com) library;
1. The **xaringan** package;
Basically **xaringan** injected the chakra of R Markdown (minus Pandoc) into **remark.js**. The slides are rendered by remark.js in the web browser, and the Markdown source needed by remark.js is generated from R Markdown (**knitr**).
---
# remark.js
You can see an introduction of remark.js from [its homepage](https://remarkjs.com). You should read the [remark.js Wiki](https://github.com/gnab/remark/wiki) at least once to know how to
- create a new slide (Markdown syntax<sup>*</sup> and slide properties);
- format a slide (e.g. text alignment);
- configure the slideshow;
- and use the presentation (keyboard shortcuts).
It is important to be familiar with remark.js before you can understand the options in **xaringan**.
.footnote[[*] It is different with Pandoc's Markdown! It is limited but should be enough for presentation purposes. Come on... You do not need a slide for the Table of Contents! Well, the Markdown support in remark.js [may be improved](https://github.com/gnab/remark/issues/142) in the future.]
---
background-image: url(`r xaringan:::karl`)
background-size: cover
class: center, bottom, inverse
# I was so happy to have discovered remark.js!
---
class: inverse, middle, center
# Using xaringan
---
# xaringan
Provides an R Markdown output format `xaringan::moon_reader` as a wrapper for remark.js, and you can use it in the YAML metadata, e.g.
```yaml
---
title: "A Cool Presentation"
output:
xaringan::moon_reader:
yolo: true
nature:
autoplay: 30000
---
```
See the help page `?xaringan::moon_reader` for all possible options that you can use.
---
# remark.js vs xaringan
Some differences between using remark.js (left) and using **xaringan** (right):
.pull-left[
1. Start with a boilerplate HTML file;
1. Plain Markdown;
1. Write JavaScript to autoplay slides;
1. Manually configure MathJax;
1. Highlight code with `*`;
1. Edit Markdown source and refresh browser to see updated slides;
]
.pull-right[
1. Start with an R Markdown document;
1. R Markdown (can embed R/other code chunks);
1. Provide an option `autoplay`;
1. MathJax just works;<sup>*</sup>
1. Highlight code with `{{}}`;
1. The RStudio addin "Infinite Moon Reader" automatically refreshes slides on changes;
]
.footnote[[*] Not really. See next page.]
---
# Math Expressions
You can write LaTeX math expressions inside a pair of dollar signs, e.g. $\alpha+\beta$ renders $\alpha+\beta$. You can use the display style with double dollar signs:
```
$$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$
```
$$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$
Limitations:
1. The source code of a LaTeX math expression must be in one line, unless it is inside a pair of double dollar signs, in which case the starting `$$` must appear in the very beginning of a line, followed immediately by a non-space character, and the ending `$$` must be at the end of a line, led by a non-space character;
1. There should not be spaces after the opening `$` or before the closing `$`.
1. Math does not work on the title slide (see [#61](https://github.com/yihui/xaringan/issues/61) for a workaround).
---
# R Code
```{r comment='#'}
# a boring regression
fit = lm(dist ~ 1 + speed, data = cars)
coef(summary(fit))
dojutsu = c('地爆天星', '天照', '加具土命', '神威', '須佐能乎', '無限月読')
grep('天', dojutsu, value = TRUE)
```
---
# R Plots
```{r cars, fig.height=4, dev='svg'}
par(mar = c(4, 4, 1, .1))
plot(cars, pch = 19, col = 'darkgray', las = 1)
abline(fit, lwd = 2)
```
---
# Tables
If you want to generate a table, make sure it is in the HTML format (instead of Markdown or other formats), e.g.,
```{r}
knitr::kable(head(iris), format = 'html')
```
---
# HTML Widgets
I have not thoroughly tested HTML widgets against **xaringan**. Some may work well, and some may not. It is a little tricky.
Similarly, the Shiny mode (`runtime: shiny`) does not work. I might get these issues fixed in the future, but these are not of high priority to me. I never turn my presentation into a Shiny app. When I need to demonstrate more complicated examples, I just launch them separately. It is convenient to share slides with other people when they are plain HTML/JS applications.
See the next page for two HTML widgets.
---
```{r out.width='100%', fig.height=6, eval=require('leaflet')}
library(leaflet)
leaflet() %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 17)
```
---
```{r eval=require('DT'), tidy=FALSE}
DT::datatable(
head(iris, 10),
fillContainer = FALSE, options = list(pageLength = 8)
)
```
---
# Some Tips
- Do not forget to try the `yolo` option of `xaringan::moon_reader`.
```yaml
output:
xaringan::moon_reader:
yolo: true
```
---
# Some Tips
- Slides can be automatically played if you set the `autoplay` option under `nature`, e.g. go to the next slide every 30 seconds in a lightning talk:
```yaml
output:
xaringan::moon_reader:
nature:
autoplay: 30000
```
- If you want to restart the play after it reaches the last slide, you may set the sub-option `loop` to TRUE, e.g.,
```yaml
output:
xaringan::moon_reader:
nature:
autoplay:
interval: 30000
loop: true
```
---
# Some Tips
- A countdown timer can be added to every page of the slides using the `countdown` option under `nature`, e.g. if you want to spend one minute on every page when you give the talk, you can set:
```yaml
output:
xaringan::moon_reader:
nature:
countdown: 60000
```
Then you will see a timer counting down from `01:00`, to `00:59`, `00:58`, ... When the time is out, the timer will continue but the time turns red.
---
# Some Tips
- The title slide is created automatically by **xaringan**, but it is just another remark.js slide added before your other slides.
The title slide is set to `class: center, middle, inverse, title-slide` by default. You can change the classes applied to the title slide with the `titleSlideClass` option of `nature` (`title-slide` is always applied).
```yaml
output:
xaringan::moon_reader:
nature:
titleSlideClass: [top, left, inverse]
```
--
- If you'd like to create your own title slide, disable **xaringan**'s title slide with the `seal = FALSE` option of `moon_reader`.
```yaml
output:
xaringan::moon_reader:
seal: false
```
---
# Some Tips
- There are several ways to build incremental slides. See [this presentation](https://slides.yihui.org/xaringan/incremental.html) for examples.
- The option `highlightLines: true` of `nature` will highlight code lines that start with `*`, or are wrapped in `{{ }}`, or have trailing comments `#<<`;
```yaml
output:
xaringan::moon_reader:
nature:
highlightLines: true
```
See examples on the next page.
---
# Some Tips
.pull-left[
An example using a leading `*`:
```r
if (TRUE) {
** message("Very important!")
}
```
Output:
```r
if (TRUE) {
* message("Very important!")
}
```
This is invalid R code, so it is a plain fenced code block that is not executed.
]
.pull-right[
An example using `{{}}`:
````
`r ''````{r tidy=FALSE}
if (TRUE) {
*{{ message("Very important!") }}
}
```
````
Output:
```{r tidy=FALSE}
if (TRUE) {
{{ message("Very important!") }}
}
```
It is valid R code so you can run it. Note that `{{}}` can wrap an R expression of multiple lines.
]
---
# Some Tips
An example of using the trailing comment `#<<` to highlight lines:
````markdown
`r ''````{r tidy=FALSE}
library(ggplot2)
ggplot(mtcars) +
aes(mpg, disp) +
geom_point() + #<<
geom_smooth() #<<
```
````
Output:
```{r tidy=FALSE, eval=FALSE}
library(ggplot2)
ggplot(mtcars) +
aes(mpg, disp) +
geom_point() + #<<
geom_smooth() #<<
```
---
# Some Tips
When you enable line-highlighting, you can also use the chunk option `highlight.output` to highlight specific lines of the text output from a code chunk. For example, `highlight.output = TRUE` means highlighting all lines, and `highlight.output = c(1, 3)` means highlighting the first and third line.
````md
`r ''````{r, highlight.output=c(1, 3)}
head(iris)
```
````
```{r, highlight.output=c(1, 3), echo=FALSE}
head(iris)
```
Question: what does `highlight.output = c(TRUE, FALSE)` mean? (Hint: think about R's recycling of vectors)
---
# Some Tips
- To make slides work offline, you need to download a copy of remark.js in advance, because **xaringan** uses the online version by default (see the help page `?xaringan::moon_reader`).
- You can use `xaringan::summon_remark()` to download the latest or a specified version of remark.js. By default, it is downloaded to `libs/remark-latest.min.js`.
- Then change the `chakra` option in YAML to point to this file, e.g.
```yaml
output:
xaringan::moon_reader:
chakra: libs/remark-latest.min.js
```
- If you used Google fonts in slides (the default theme uses _Yanone Kaffeesatz_, _Droid Serif_, and _Source Code Pro_), they won't work offline unless you download or install them locally. The Heroku app [google-webfonts-helper](https://google-webfonts-helper.herokuapp.com/fonts) can help you download fonts and generate the necessary CSS.
---
# Macros
- remark.js [allows users to define custom macros](https://github.com/yihui/xaringan/issues/80) (JS functions) that can be applied to Markdown text using the syntax `![:macroName arg1, arg2, ...]` or ``. For example, before remark.js initializes the slides, you can define a macro named `scale`:
```js
remark.macros.scale = function (percentage) {
var url = this;
return '<img src="' + url + '" style="width: ' + percentage + '" />';
};
```
Then the Markdown text
```markdown

```
will be translated to
```html
<img src="image.jpg" style="width: 50%" />
```
---
# Macros (continued)
- To insert macros in **xaringan** slides, you can use the option `beforeInit` under the option `nature`, e.g.,
```yaml
output:
xaringan::moon_reader:
nature:
beforeInit: "macros.js"
```
You save your remark.js macros in the file `macros.js`.
- The `beforeInit` option can be used to insert arbitrary JS code before `remark.create()`. Inserting macros is just one of its possible applications.
---
# CSS
Among all options in `xaringan::moon_reader`, the most challenging but perhaps also the most rewarding one is `css`, because it allows you to customize the appearance of your slides using any CSS rules or hacks you know.
You can see the default CSS file [here](https://github.com/yihui/xaringan/blob/master/inst/rmarkdown/templates/xaringan/resources/default.css). You can completely replace it with your own CSS files, or define new rules to override the default. See the help page `?xaringan::moon_reader` for more information.
---
# CSS
For example, suppose you want to change the font for code from the default "Source Code Pro" to "Ubuntu Mono". You can create a CSS file named, say, `ubuntu-mono.css`:
```css
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
```
Then set the `css` option in the YAML metadata:
```yaml
output:
xaringan::moon_reader:
css: ["default", "ubuntu-mono.css"]
```
Here I assume `ubuntu-mono.css` is under the same directory as your Rmd.
See [yihui/xaringan#83](https://github.com/yihui/xaringan/issues/83) for an example of using the [Fira Code](https://github.com/tonsky/FiraCode) font, which supports ligatures in program code.
---
# CSS (with Sass)
**xaringan** also supports Sass support via **rmarkdown**. Suppose you want to use the same color for different elements, e.g., first heading and bold text. You can create a `.scss` file, say `mytheme.scss`, using the [sass](https://sass-lang.com/) syntax with variables:
```scss
$mycolor: #ff0000;
.remark-slide-content > h1 { color: $mycolor; }
.remark-slide-content strong { color: $mycolor; }
```
Then set the `css` option in the YAML metadata using this file placed under the same directory as your Rmd:
```yaml
output:
xaringan::moon_reader:
css: ["default", "mytheme.scss"]
```
This requires **rmarkdown** >= 2.8 and the [**sass**](https://rstudio.github.io/sass/) package. You can learn more about **rmarkdown** and **sass** support in [this blog post](https://blog.rstudio.com/2021/04/15/2021-spring-rmd-news/#sass-and-scss-support-for-html-based-output) and in [**sass** overview vignette](https://rstudio.github.io/sass/articles/sass.html).
---
# Themes
Don't want to learn CSS? Okay, you can use some user-contributed themes. A theme typically consists of two CSS files `foo.css` and `foo-fonts.css`, where `foo` is the theme name. Below are some existing themes:
```{r, R.options=list(width = 70)}
names(xaringan:::list_css())
```
---
# Themes
To use a theme, you can specify the `css` option as an array of CSS filenames (without the `.css` extensions), e.g.,
```yaml
output:
xaringan::moon_reader:
css: [default, metropolis, metropolis-fonts]
```
If you want to contribute a theme to **xaringan**, please read [this blog post](https://yihui.org/en/2017/10/xaringan-themes).
---
class: inverse, middle, center
background-image: url(https://upload.wikimedia.org/wikipedia/commons/3/39/Naruto_Shiki_Fujin.svg)
background-size: contain
# Naruto
---
background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg)
background-size: 100px
background-position: 90% 8%
# Sharingan
The R package name **xaringan** was derived<sup>1</sup> from **Sharingan**, a dōjutsu in the Japanese anime _Naruto_ with two abilities:
- the "Eye of Insight"
- the "Eye of Hypnotism"
I think a presentation is basically a way to communicate insights to the audience, and a great presentation may even "hypnotize" the audience.<sup>2,3</sup>
.footnote[
[1] In Chinese, the pronounciation of _X_ is _Sh_ /ʃ/ (as in _shrimp_). Now you should have a better idea of how to pronounce my last name _Xie_.
[2] By comparison, bad presentations only put the audience to sleep.
[3] Personally I find that setting background images for slides is a killer feature of remark.js. It is an effective way to bring visual impact into your presentations.
]
---
# Naruto terminology
The **xaringan** package borrowed a few terms from Naruto, such as
- [Sharingan](https://naruto.fandom.com/wiki/Sharingan) (写輪眼; the package name)
- The [moon reader](https://naruto.fandom.com/wiki/Moon_Reader) (月読; an attractive R Markdown output format)
- [Chakra](https://naruto.fandom.com/wiki/Chakra) (查克拉; the path to the remark.js library, which is the power to drive the presentation)
- [Nature transformation](https://naruto.fandom.com/wiki/Nature_Transformation) (性質変化; transform the chakra by setting different options)
- The [infinite moon reader](https://naruto.fandom.com/wiki/Infinite_Tsukuyomi) (無限月読; start a local web server to continuously serve your slides)
- The [summoning technique](https://naruto.fandom.com/wiki/Summoning_Technique) (download remark.js from the web)
You can click the links to know more about them if you want. The jutsu "Moon Reader" may seem a little evil, but that does not mean your slides are evil.
---
class: center
# Hand seals (印)
Press `h` or `?` to see the possible ninjutsu you can use in remark.js.

---
class: center, middle
# Thanks!
Slides created via the R package [**xaringan**](https://github.com/yihui/xaringan).
The chakra comes from [remark.js](https://remarkjs.com), [**knitr**](https://yihui.org/knitr/), and [R Markdown](https://rmarkdown.rstudio.com).
| /scratch/gouwar.j/cran-all/cranData/xaringan/inst/rmarkdown/templates/xaringan/skeleton/skeleton.Rmd |
---
title: "幻灯忍者"
subtitle: "写轮眼"
author: "谢益辉"
institute: "RStudio, PBC"
date: "2016/12/12"
output:
xaringan::moon_reader:
css: [default, zh-CN.css]
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg)
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
???
图片来源:[Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Sharingan_triple.svg)
---
class: center, middle
# xaringan
### /ʃaː.'riŋ.ɡan/
---
class: inverse, center, middle
# 出发!
---
# 你好世界
首先从 [Github](https://github.com/yihui/xaringan) 安装 **xaringan** 包:
```{r tidy=FALSE}
if (!requireNamespace("xaringan"))
remotes::install_github("yihui/xaringan")
```
--
除非你是六指琴魔,否则我建议安装 [RStudio 编辑器](https://www.rstudio.com/products/rstudio/),它会让你做幻灯片做得飞起。
- 从菜单 `File -> New File -> R Markdown -> From Template -> Ninja Presentation (Simplified Chinese)` 创建一个新文档;
--
- 点击 `Knit` 按钮编译文档;
--
- 或者点击 [RStudio 插件](https://rstudio.github.io/rstudioaddins/)<sup>*</sup> “Infinite Moon Reader” 在 RStudio 里实时预览幻灯片(每次你保存文档的时候,它会自动重新编译);
.footnote[[*] 如果你看不到模板或者插件,请参见 [#2](https://github.com/yihui/xaringan/issues/2),你的某些 R 包可能崩坏了,需要重新安装。]
---
background-image: url(`r xaringan:::karl`)
background-position: 50% 50%
class: center, bottom, inverse
### 洛阳亲友如相问,请你不要告诉他
(我是怎么做幻灯片的)
---
# 你好忍者
忍者不会停留在“你好世界”里,要用好这个 R 包,你需要了解:
1. JavaScript 库 [remark.js](https://remarkjs.com) 的语法;
1. **xaringan** 包中的选项;
**xaringan** 将 R Markdown 的查克拉注入了 **remark.js**。浏览器中的幻灯片是 remark.js 渲染出来的,而它的 Markdown 源文档是从 R Markdown 生成的(实际上主要是 **knitr**)。
---
# remark.js
关于 remark.js 的用法可参考它的[首页](https://remarkjs.com),由于伟大的墙,你可能打不开这个页面(因为里面用了 Google 字体)。不过 [remark.js 的维基页面](https://github.com/gnab/remark/wiki) 已经有足够的信息了,你需要学习:
- 如何创建一页新的片子,主要是 Markdown 语法<sup>*</sup> 以及单页片子的属性设置;
- 如何排版,例如文本对齐;
- 如何设置整个幻灯片的选项(代码高亮样式之类的);
- 怎样播放幻灯片(快捷键,按 `h` 键基本就知道了);
.footnote[[*] 它和 Pandoc Markdown 语法不同,不过对做幻灯片而言,简单的语法可能也足够了。]
---
background-image: url(`r xaringan:::karl`)
background-size: cover
class: center, bottom, inverse
### 唔,remark.js,朕很满意!
---
class: inverse, middle, center
# xaringan 包的使用
---
# xaringan
**xaringan** 包提供了一个 R Markdown 输出格式 `xaringan::moon_reader`,你可以在 R Markdown 文档的元数据中使用它,例:
```yaml
---
title: "啧啧啧,厉害啊"
author: "张三"
date: "2016年12月12日"
output:
xaringan::moon_reader
nature:
autoplay: 30000
highlightStyle: github
---
```
欲知所有可能的选项,参见 R 帮助文档 `?xaringan::moon_reader`。
---
# remark.js 与 xaringan 的区别
remark.js (左)与 **xaringan** (右):
.pull-left[
1. 需要一个 HTML 容器文件;
1. 只能用 Markdown;
1. 若想自动播放幻灯片需要写 JavaScript;
1. 需手工配置 MathJax;
1. 用 `*` 高亮一行代码;
1. 编辑 Markdown 之后需要刷新浏览器看结果;
]
.pull-right[
1. 用 R Markdown 文档生成幻灯片;
1. Markdown 里可以嵌入 R 代码;
1. 可用 `autoplay` 选项自动播放;
1. MathJax 无需特别配置;<sup>*</sup>
1. 用 `{{}}` 高亮一行代码;
1. 用 RStudio 插件“Infinite Moon Reader”自动预览幻灯片;
]
.footnote[[*] 下一页有数学公式例子。]
---
# 数学公式
数学公式用 LaTeX 语法写在一对美元符号中间,例如 $\alpha+\beta$ 会生成 $\alpha+\beta$。若要将公式单独显示为一个段落,可以用一对双重美元符号:
```
$$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$
```
$$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$
局限性:
1. 公式的源代码只能写在一行上,不能换行;双重美元符号内的公式允许换行,但条件是起始标记 `$$` 必须在一行的最开头(前面不能有任何字符,后面必须跟一个不是空格的字符),结束标记 `$$` 必须在一行的最末尾(前面必须是一个非空格的字符,后面不能有任何字符);
1. 起始美元符号后以及结束美元符号前不能有空格,否则不会被识别为公式;
---
# R 代码
```{r comment='#'}
# 一个无聊的回归模型
fit = lm(dist ~ 1 + speed, data = cars)
coef(summary(fit))
dojutsu = c('地爆天星', '天照', '加具土命', '神威', '須佐能乎', '無限月読')
grep('天', dojutsu, value = TRUE)
```
---
# R 图形
```{r cars, fig.height=3.5, dev='svg'}
par(mar = c(4, 4, 1, .1))
plot(cars, pch = 19, col = 'darkgray', las = 1)
abline(fit, lwd = 2)
```
---
# HTML 控件
我没有仔细测试 [HTML 控件](https://htmlwidgets.org),祝你好运。下一页上有两个例子,一个地图,一个表格,目测貌似可用。
目前也不支持 Shiny 模式(即 `runtime: shiny`)。还是别把你的幻灯片搞辣么复杂吧。
---
```{r out.width='100%', fig.height=6, eval=require('leaflet')}
library(leaflet)
leaflet() %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 17)
```
---
```{r eval=require('DT'), tidy=FALSE}
DT::datatable(
head(iris, 10),
fillContainer = FALSE, options = list(pageLength = 8)
)
```
---
# 一些小技能
- “Infinite Moon Reader”插件默认情况下会锁住你的 R 进程,有它没你,有你没它。你可以设置一个选项,让它一边儿凉快去:
```r
options(servr.daemon = TRUE)
```
你可以把这个设置写在 `~/.Rprofile` 文件中,这样你将来所有 R 进程都不会被这个插件挡住去路。
这事情背后的魔法在 [**servr**](https://github.com/yihui/servr) 包中。
--
- 别忘了玩一下 `yolo` 选项,如:
```yaml
output:
xaringan::moon_reader:
yolo: 3
```
它会随机显示 Karl Broman 的照片;这里地方太小,写不下故事的来龙去脉。
---
# 一些小技能
- `nature` 下面的 `autoplay` 选项可以用来自动播放幻灯片,它的取值是毫秒,例如每 30 秒播放一张片子:
```yaml
output:
xaringan::moon_reader:
nature:
autoplay: 30000
```
--
- `nature` 下面的 `countdown` 选项可以为每一页幻灯片添加一个(倒数)计时器,取值同样为毫秒,例如每一页片子都用 60 秒倒计时:
```yaml
output:
xaringan::moon_reader:
nature:
countdown: 60000
```
---
# 一些小技能
- 一页片子可以分割成一步步播放,参见[这个示例](https://slides.yihui.org/xaringan/incremental.html)。
- 选项 `highlightLines: true` 可以让以 `*` 开头或者双重大括号 `{{ }}` 里面的代码被高亮出来;
```yaml
output:
xaringan::moon_reader:
nature:
highlightLines: true
```
下一页我们举两个栗子。
---
# 一些小技能
.pull-left[
以 `*` 开头的代码:
```r
if (TRUE) {
** message("敲黑板!划重点!")
}
```
输出:
```r
if (TRUE) {
* message("敲黑板!划重点!")
}
```
因为它不是合法的 R 代码,所以不能作为 R 代码段来写,只能用三个反引号直接跟 r(就知道你没听懂)。
]
.pull-right[
用 `{{}}` 包裹的代码:
````
`r ''````{r tidy=FALSE}
if (TRUE) {
*{{ message("敲黑板!划重点!") }}
}
```
````
输出:
```{r tidy=FALSE}
if (TRUE) {
{{ message("敲黑板!划重点!") }}
}
```
这是合法的 R 代码,所以你可以真的运行它。
]
---
# CSS(层叠样式表)
`xaringan::moon_reader` 的所有选项中,最强的魔法在 `css` 选项上,它是自定义幻灯片样式的关键。如果你不懂 CSS 的话,我强烈建议你学习一些 CSS 的基础知识。
对中文幻灯片,**xaringan** 包中的默认 CSS 文件在[这里](https://github.com/yihui/xaringan/blob/master/inst/rmarkdown/templates/xaringan_zh-CN/skeleton/zh-CN.css),你可以在它的基础上改装,也可以直接定义全新的 CSS 样式。
---
# CSS(层叠样式表)
举个栗子。比如你想将一段文字的颜色改为红色,你可以定义一个 CSS 类,如:
```css
.red {
color: #FF0000;
}
```
我们把这段代码保存在一个 CSS 文件中,如 `extra.css`(假设它跟你的 R Markdown 文件在同一文件夹下),然后通过 `css` 选项将它引入:
```yaml
output:
xaringan::moon_reader:
css: ["zh-CN.css", "extra.css"]
```
其中 `zh-CN.css` 是本包已经为你提供的 CSS 样式文件(你可选择用或不用)。
现在在 R Markdown 中你就可以用 `.red[]` 来标记一段文字为红色,如 `.red[我是红色的]`。
---
# CSS(层叠样式表)
如果想在墙内用 Google 字体的话,可以试试这个 [google-webfonts-helper](https://google-webfonts-helper.herokuapp.com/fonts) 应用,它会把字体下载到本地并生成相应的 CSS 文件。也可以考虑 360 的 [CDN 服务](http://libs.useso.com)。
可惜中文不像英文,没有很新奇酷炫的网络字体,只能靠你电脑上的字体硬撑了。
---
class: inverse, middle, center
background-image: url(https://upload.wikimedia.org/wikipedia/commons/3/39/Naruto_Shiki_Fujin.svg)
background-size: contain
# 火影忍者
---
background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg)
background-size: 100px
background-position: 90% 8%
# 写轮眼
**xaringan** 这个名字来源于火影中的写轮眼 **Sharingan**。<sup>1</sup> 写轮眼有两大能力:
- 洞察眼
- 催眠眼
其实做演示就是将自己的洞见传递给听众;好的演讲通常有催眠效果,因为它可以深度震撼人心。<sup>2,3</sup>
.footnote[
[1] 我把 Sh 换成 X 了,因为几乎没有一个歪果仁读对过我的姓。当然主要原因还是 xaringan 搜索起来更容易被搜到。
[2] 糟糕的演讲也可以催眠听众,但显然这两种催眠完全不同。
[3] 我之所以选择了 remark.js 框架,就是因为它可以设置背景图。对我而言,在一页片子上整页显示一幅图最能表达震撼的视觉效果,现有的 R Markdown 幻灯片框架都缺乏这个功能,不开森。当时我发现 remark.js 之后真的是激动地不要不要的,等了一个月才抽出空来把这个包写出来。
]
---
# 火影术语
简单介绍一下这个包里那些奇怪的术语的由来:
- [写轮眼](https://naruto.fandom.com/wiki/Sharingan)(包名,已解释)
- [月读](https://naruto.fandom.com/wiki/Moon_Reader)(我希望这个 R Markdown 格式 `moon_reader` 能将听众控制在幻象中)
- [查克拉](https://naruto.fandom.com/wiki/Chakra)(月读的参数之一 `chakra`,意思是 remark.js 的路径,它是支撑幻灯片的核心动力)
- [性质变化](https://naruto.fandom.com/wiki/Nature_Transformation)(月读的参数之一 `nature`,意思是通过设置选项改变查克拉的性质)
- [无限月读](https://naruto.fandom.com/wiki/Infinite_Tsukuyomi)(函数 `infinite_moon_reader()` 开启一个服务器不断刷新更新后的幻灯片,RStudio 插件背后对应的就是这个函数)
- [通灵术](https://naruto.fandom.com/wiki/Summoning_Technique)(`summon_remark()` 从网络上把 remark.js 通灵到本地)
月读这个忍术有点邪恶,不过你就当不知道吧。
---
# 结印
使用本包单手就可以结印,按键 `h` 或者 `?` 之后就可以看见所有结印手势,例如 `p` 进入演讲者模式(可看见写给自己的注释,比如提醒自己要讲的笑话),`c` 复制幻灯片到新窗口;演讲时可以在自己面前的屏幕上显示演讲者模式,把新窗口中正常的幻灯片拖到大屏幕投影上给观众看。
.center[]
???
嗯,我们来讲一个不容易看懂的冷笑话。

---
class: center, middle
# 蟹蟹
本幻灯片由 R 包 [**xaringan**](https://github.com/yihui/xaringan) 生成;
查克拉来自于 [remark.js](https://remarkjs.com)、[**knitr**](https://yihui.org/knitr)、以及 [R Markdown](https://rmarkdown.rstudio.com)。
| /scratch/gouwar.j/cran-all/cranData/xaringan/inst/rmarkdown/templates/xaringan_zh-CN/skeleton/skeleton.Rmd |
#' Animate.css
#'
#' Animate.css is a popular collection of CSS animations. It contains "a
#' bunch of cool, fun, and cross-browser animations for you to use in your
#' projects. Great for emphasis, home pages, sliders, and general
#' just-add-water-awesomeness."
#'
#' @section Usage: To add animate.css to your xaringan presentation, add the
#' following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringan-animate, echo=FALSE}
#' xaringanExtra::use_animate_css()
#' ```
#'
#' ---
#' class: animated fadeInLeft slideOutRight
#'
#' This slide fades in from the left and slides out to the right!
#' ````
#'
#' Note that when `xaringan = TRUE`, as is the default, out animations are
#' only applied to slides that are exiting so that you can specify both in
#' and out behavior of each slide.
#'
#' Or use `use_animate_all()` to set default in and out animations for all
#' slides. Animations can be disabled for individual slides by adding the
#' class `.no-animation` to the slide.
#'
#' ````markdown
#' ```{r xaringan-animate, echo=FALSE}
#' xaringanExtra::use_animate_all("slide_left")
#' ```
#' ````
#'
#' @examples
#' use_animate_css()
#' html_dependency_animate_css()
#'
#' @references See [animate.css](https://daneden.github.io/animate.css/) for a
#' full list of animations.
#'
#' @param minified Should the minified or full CSS source be used?
#' @param xaringan When `TRUE`, the `.animated` selector is modified so that the
#' animation is only applied when the slide is visible. Without this,
#' presentations with many animated slides may have poor performance,
#' especially on page load. Set to `FALSE` to use animate.css in other
#' HTML-based documents.
#'
#' @return An `htmltools::tagList()` with the tile view dependencies, or an
#' [htmltools::htmlDependency()].
#'
#' @name animate_css
NULL
#' @describeIn animate_css Use animate.css in your xaringan slides.
#' @export
use_animate_css <- function(minified = FALSE, xaringan = TRUE) {
htmltools::tagList(
html_dependency_animate_css(minified, xaringan)
)
}
#' @describeIn animate_css Returns an [htmltools::htmlDependency()] with the tile
#' view dependencies. Most users will want to use `use_animate_css()`.
#' @export
html_dependency_animate_css <- function(minified = FALSE, xaringan = TRUE) {
css_file <- "animate"
if (xaringan) css_file <- paste0(css_file, ".xaringan")
if (minified) css_file <- paste0(css_file, ".min")
css_file <- paste0(css_file, ".css")
htmltools::htmlDependency(
name = "animate.css",
version = "3.7.2",
package = "xaringanExtra",
src = "animate-css",
stylesheet = css_file,
all_files = FALSE
)
}
#' @describeIn animate_css Use a default animation for all slides. Sets coupled
#' in an out animations for all slides that can be disabled on individual
#' slides by adding the class `.no-animation`.
#' @param style Animation style to be used for all slides.
#'
#' - `slide_left`: Slide in from the right and out to the left
#' - `slide_right`: Slide in from the left and out to the right
#' - `slide_up`: Slide in from the bottom and out to the top
#' - `slide_down`: Slide in from the top and out to the bottom
#' - `roll`: Roll in from the left and roll out to the right
#' - `fade`: Fade in
#' @export
use_animate_all <- function(style = c(
"slide_left",
"slide_right",
"slide_up",
"slide_down",
"roll",
"fade"
)) {
css_file <- paste0("animate.", match.arg(style), ".css")
htmltools::tagList(
htmltools::htmlDependency(
name = "animate.css-xaringan",
version = "3.7.2",
package = "xaringanExtra",
src = "animate-css",
stylesheet = css_file,
all_files = FALSE
)
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/animate.R |
#' Add a banner to the top or bottom of your slides.
#'
#' Adds a banner to all the slides in your deck at the top or the bottom of the
#' slide. You can place content in the left, center, or right portion of the
#' banner.
#'
#' @examples
#' use_banner(bottom_left = "bit.ly/my-awesome-slides")
#'
#' use_banner(
#' bottom_left = "bit.ly/my-awesome-slides",
#' top_center = "My Presentation",
#' exclude = c("title-slide", "inverse"),
#' style_banner(text_color = "grey")
#' )
#'
#' @param bottom_left,top_left Text or HTML to place in the left column of the
#' top or bottom of the slide.
#' @param bottom_right,top_right Text or HTML to place in the right column of
#' the top or bottom of the slide.
#' @param bottom_center,top_center Text or HTML to place in the center column
#' at the top or the bottom of the slide.
#' @param exclude A vector of slide classes where the banner should not be
#' applied. By default all slides are included, but you might want to exclude
#' the title and inverse slides with `exclude = c("title-slide", "inverse")`.
#' @param ... Banner styles created with [style_banner()]. Technically,
#' additional arguments are added into the [htmltools::tagList()] with the
#' banner dependencies, but you'll only want to use [style_banner()] calls
#' here.
#'
#' @return An [htmltools::tagList()] with the banner dependencies, or an
#' [htmltools::htmlDependency].
#'
#' @seealso [style_banner()]
#' @export
use_banner <- function(
...,
bottom_left = NULL,
bottom_center = NULL,
bottom_right = NULL,
top_left = NULL,
top_center = NULL,
top_right = NULL,
exclude = NULL
) {
top <- init_banner(top_left, top_center, top_right, "top", exclude)
bottom <- init_banner(bottom_left, bottom_center, bottom_right, "bottom", exclude)
htmltools::tagList(
top,
bottom,
...,
htmltools::htmlDependency(
name = "xaringanExtra-banner",
version = "0.0.1",
package = "xaringanExtra",
src = "banner",
script = "banner.js",
stylesheet = "banner.css",
all_files = FALSE
)
)
}
#' Style Banner
#'
#' Change the banner style properties for a specific selector. By default, the
#' changes apply to all banners, but by setting `selector` you can apply style
#' changes to the banners of specific slide styles. For example, to set the
#' styles for inverse slides, use `selector = ".inverse"`.
#'
#' @examples
#' style_banner(text_color = "red")
#' style_banner(text_color = "white", background_color = "red")
#'
#' @param text_color The color of text in the banners which may be overridden by
#' other styles, e.g. link color, etc. The default value inherits from the
#' primary text color of the slide.
#' @param background_color The color of the banner background. By default
#' the background is transparent.
#' @param padding_horizontal,padding_vertical The inner padding of the banner.
#' By default no padding is applied in the vertical direction, but `2em` of
#' padding is applied horizontally. If anything, you probably only want to
#' change the value of `padding_horizontal`.
#' @param height The height of the banner in a valid CSS unit.
#' @param width The maximum width of each column in the banner. You can set the
#' width for all columns with a single valid CSS unit, or you may provide a
#' vector of CSS units, named `"left"`, `"center"`, or `"right"` or provided
#' in that order.
#' @param font_size,font_family The font size and family of the text in the
#' banner. The default font size is `0.7em` and the default family inherits
#' from the primary text of the slide.
#' @param z_index The z-index of the banner. By default this value is 0 so that
#' all other content appears over the banner. To ensure the banner appears
#' *above slide content*, you can set `z_index` to something greater than 0.
#' @param selector A CSS selector, e.g. `".inverse"`, where the styles set in
#' this call should be applied. Typically, you'll either set these styles for
#' all banners using the default `selector`, or you'll want to customize the
#' banner appearance for particular slide classes. Note that you can call
#' `style_banner()` as many times as you want in your slides, but you'll want
#' to change the `selector` for each call.
#'
#' @return Returns a `<style>` tag with the banner styles for `selector` as
#' HTML via [htmltools::HTML()].
#'
#' @seealso [use_banner()]
#' @export
style_banner <- function(
text_color = NULL,
background_color = NULL,
padding_horizontal = NULL,
padding_vertical = NULL,
height = NULL,
width = NULL,
font_size = NULL,
font_family = NULL,
z_index = NULL,
selector = ":root"
) {
assert_len_1 <- function(x) {
var <- deparse(substitute(x))
if (is.null(x) || length(x) <= 1) {
return(x)
}
stop(sprintf("`%s` must be length-1", var))
}
assert_len_1(selector)
css <- list(
fg = assert_len_1(text_color),
bg = assert_len_1(background_color),
height = assert_len_1(height),
"z-index" = assert_len_1(z_index),
"padding-x" = assert_len_1(padding_horizontal),
"padding-y" = assert_len_1(padding_vertical),
"font-size" = assert_len_1(font_size),
"font-family" = assert_len_1(font_family)
)
css <- style_banner_width(css, width)
css <- compact(css)
if (!length(css)) {
return(invisible())
}
unit_vars <- c(
"padding-x", "padding-y", "height", "font-size",
"width-left", "width-right", "width-center"
)
unit_vars <- intersect(unit_vars, names(css))
for (unit_var in unit_vars) {
if (!css[[unit_var]] %in% c("inherit", "unset", "initial", "revert")) {
css[[unit_var]] <- htmltools::validateCssUnit(css[[unit_var]])
}
}
names(css) <- paste0("--xe-banner-", names(css))
css <- paste(sprintf(" %s: %s;", names(css), unlist(css)), collapse = "\n")
css <- sprintf("%s {\n%s\n}", selector, css)
htmltools::tags$style(htmltools::HTML(css))
}
style_banner_width <- function(css, width) {
if (is.null(width)) {
return(css)
}
if (length(width) < 1 || length(width) > 3) {
stop(
"`width` must be named vector or at most length 3 ",
"('left', 'center', 'right')"
)
}
if (length(width) == 1) {
width <- rep(width, 3)
}
if (is.null(names(width))) {
names(width) <- c("left", "center", "right")[1:length(width)]
} else {
bad <- setdiff(names(width), c("left", "center", "right"))
if (length(bad)) {
stop(
"`width` contains unexpected names: ",
paste(bad, collapse = ", ")
)
}
}
names(width) <- paste0("width-", names(width))
c(css, width)
}
init_banner <- function(
left = NULL,
center = NULL,
right = NULL,
position = "bottom",
exclude = NULL
) {
opts <- compact(list(left = left, center = center, right = right, exclude = exclude))
opts <- lapply(opts, function(x) {
if (!is.character(x)) {
x <- format(x)
}
paste(x, collapse = " ")
})
if (length(opts)) {
opts$position <- position
if (!is.null(opts$exclude)) {
opts$exclude <- I(opts$exclude)
}
opts <- sprintf(
"<script>document.addEventListener('DOMContentLoaded',function(){new xeBanner(JSON.parse('%s'))})</script>",
jsonlite::toJSON(opts, auto_unbox = TRUE)
)
opts <- gsub('\\\\"', '\\\\\\\\"', opts)
htmltools::HTML(opts)
}
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/banner.R |
#' Broadcast Your Slides
#'
#' [Experimental](https://lifecycle.r-lib.org/articles/stages.html)!
#' **Broadcast** lets others follow along, in real time! Built with
#' [PeerJS](https://peerjs.com), **broadcast** give you a unique URL to share
#' with your viewers. Then, when they load your slides, their slides will
#' automatically follow you as you present!
#'
#' @includeRmd man/fragments/broadcast-details.Rmd
#'
#' @examples
#' use_broadcast()
#'
#' @return An `htmltools::tagList()` with the HTML dependencies required for
#' **broadcast**.
#'
#' @references <https://peerjs.com>
#' @export
use_broadcast <- function() {
htmltools::tagList(
html_dependency_jscookie(),
html_dependency_peerjs(),
html_dependency_tinytoast(),
html_dependency_broadcast()
)
}
html_dependency_broadcast <- function() {
htmltools::htmlDependency(
name = "xaringanExtra-broadcast",
version = "0.2.6",
package = "xaringanExtra",
src = "broadcast",
script = "broadcast.js",
stylesheet = "broadcast.css",
all_files = FALSE
)
}
html_dependency_peerjs <- function() {
htmltools::htmlDependency(
name = "peerjs",
version = "1.3.1",
package = "xaringanExtra",
src = c(
file = "jslib/peerjs",
href = "https://unpkg.com/[email protected]/dist/"
),
script = "peerjs.min.js",
all_files = TRUE
)
}
html_dependency_tinytoast <- function() {
htmltools::htmlDependency(
name = "tiny.toast",
version = "1.0.0",
package = "xaringanExtra",
src = c(
file = "jslib/tiny.toast",
href = "https://www.kirilv.com/tiny.cdn/lib/toast/1.0.0"
),
script = "toast.min.js",
all_files = TRUE
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/broadcast.R |
#' Clipboard
#'
#' Add a "Copy Code" button for one-click code chunk copying.
#'
#' @includeRmd man/fragments/clipboard-details.Rmd details
#'
#' @examples
#' use_clipboard()
#'
#' @rdname clipboard
#' @name clipboard
NULL
#' @describeIn clipboard Adds **clipboard** to your xaringan slides or R
#' Markdown HTML output.
#' @param button_text,success_text,error_text Text (or HTML) shown in the copy
#' button by default (_button_), on copy _success_, or in the event of an
#' _error_.
#' @param selector The CSS selector used to identify the elements that will
#' receive the copy code button. If `NULL`, the extension will automatically
#' choose the selector for \pkg{xaringan} slides or general R Markdown.
#'
#' The CSS selector should identify the parent container that holds the
#' content to be copied. The copy button will be added as the last element
#' in this container, and then the text of every element inside the container
#' identified by the selector, minus the copy button text, is copied to the
#' clipboard.
#' @param minified Should the minified clipboardjs dependency be used?
#'
#' @return An `htmltools::tagList()` with the HTML dependencies required for
#' **clipboard**.
#'
#' @export
use_clipboard <- function(
button_text = "Copy Code",
success_text = "Copied!",
error_text = "Press Ctrl+C to Copy",
selector = NULL,
minified = TRUE
) {
opts <- list(button = button_text, success = success_text, error = error_text)
selector <- if (!is.null(selector)) sprintf("'%s'", selector) else "null"
htmltools::tagList(
html_dependency_clipboardjs(minified),
html_dependency_clipboard(),
htmltools::htmlDependency(
name = uuid::UUIDgenerate(), # random name ensures each call ends up in <head>
version = "9.9.9",
package = "xaringanExtra",
src = "",
head = sprintf(
"<script>window.xaringanExtraClipboard(%s, %s)</script>",
selector,
jsonlite::toJSON(opts, auto_unbox = TRUE)
),
all_files = FALSE
)
)
}
#' @describeIn clipboard Returns an [htmltools::htmlDependency()] with the
#' [clipboard.js](https://clipboardjs.com/) library. For expert use.
#' @references https://clipboardjs.com/
#' @export
html_dependency_clipboardjs <- function(minified = TRUE) {
v_clipboard <- "2.0.6"
htmltools::htmlDependency(
name = "clipboard",
version = v_clipboard,
package = "xaringanExtra",
src = c(
file = "jslib/clipboard",
href = "https://unpkg.com/clipboard@2/dist/"
),
script = paste0("clipboard", if (minified) ".min", ".js"),
all_files = FALSE
)
}
#' @describeIn clipboard Returns an [htmltools::htmlDependency()] with the
#' clipboard dependencies for use in xaringan and R Markdown documents. Most
#' users will want to use `use_clipboard()` instead.
#' @export
html_dependency_clipboard <- function() {
htmltools::htmlDependency(
name = "xaringanExtra-clipboard",
version = "0.2.6",
package = "xaringanExtra",
src = "clipboard",
script = "xaringanExtra-clipboard.js",
stylesheet = "xaringanExtra-clipboard.css",
all_files = FALSE
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/clipboard.R |
#' Editable
#'
#' Editable gives you a way to write directly inside your slides. Make any
#' element of your slides editable by using the `.can-edit[...]` class. Editable
#' fields are reset when the slides are reloaded, but it is possible for edits
#' to persist across sessions (in the same browser) by giving the editable
#' element a `.key-<NAME>` class, where `<NAME>` is a unique identifier (and
#' valid CSS class).
#'
#' @examples
#' use_editable()
#'
#' @return An `htmltools::tagList()` with the editable dependencies, or an
#' [htmltools::htmlDependency].
#' @section Usage: To make your xaringan presentations _editable_, add the
#' following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringan-editable, echo=FALSE}
#' # Setup editable fields and only store values in the browser for one day
#' # (by default values expire in 2 weeks).
#' xaringanExtra::use_editable(expires = 1)
#' ```
#' ````
#'
#' Then, to make a component of your slides editable, use the `.can-edit[]`
#' class.
#'
#' ```markdown
#' ## .can-edit[You can edit this slide title]
#' ```
#'
#' Editable fields that only have the `.can-edit` class are reset whenever the
#' slides are re-loaded in your browser. If you want to store the edited
#' values and have them persist across browser sessions, give each editable
#' field a `.key-<NAME>` class. Be sure to make each key unique and note that
#' the key name must be a valid CSS class, i.e. it cannot contain spaces.
#'
#' ```markdown
#' ## .can-edit.key-firstSlideTitle[Change this title and then reload the page]
#' ```
#'
#' **Warning** Editable fields may not work well with slide continuations. If
#' your full slide builds up over several slides, you can only edit the
#' currently visible slide. If the field has a key, however, all editable
#' elements with the same key class are updated when the slides are loaded.
#' In other words, you can edit the title on the first slide of a multi-part
#' slide and reload the page to have the title applied to subsequent slides.
#'
#' @name editable
NULL
#' @describeIn editable Adds editable to your xaringan slides.
#' @param id Optional. By default, when `id` is `NULL`, each re-generation of
#' your slides creates a new document ID. This way, values that were
#' previously stored in the browser for an older version of your slides will
#' not be loaded into a new version. If you are confident that the editable
#' fields in your slides are not changing between versions, you can set the
#' document ID so that newer versions of your slides will continue to load
#' edited values from previous versions in the browser.
#' @param expires Editable values that also have a `.key-KEYNAME` class are
#' stored in the browser and automatically loaded when the slides are
#' reloaded. These values are stored using cookies so that they can eventually
#' expire and `expires` provides the number of days that those values should
#' be stored before being released.
#' @export
use_editable <- function(id = NULL, expires = 14) {
htmltools::tagList(
html_dependency_editable(expires = expires, id = id)
)
}
#' @describeIn editable Returns an [htmltools::htmlDependency] with the tile
#' view dependencies. Most users will want to use `use_editable()`.
#' @export
html_dependency_editable <- function(expires = 14, id = NULL) {
htmltools::tagList(
html_dependency_editable_id(expires = expires, id = id),
htmltools::htmlDependency(
name = "himalaya",
version = "1.1.0",
package = "xaringanExtra",
src = "jslib/himalaya",
script = "himalaya.js",
all_files = TRUE
),
html_dependency_jscookie(),
htmltools::htmlDependency(
name = "editable",
version = "0.2.6",
package = "xaringanExtra",
src = "editable",
script = "editable.js",
stylesheet = "editable.css",
all_files = FALSE
)
)
}
html_dependency_jscookie <- function() {
htmltools::htmlDependency(
name = "js-cookie",
version = "3.0.0",
package = "xaringanExtra",
src = "jslib/js-cookie",
script = "js.cookie.js",
all_files = FALSE
)
}
# Insert JSON in the document head containing editable options, in particular
# the document id and expiration time for cookies.
html_dependency_editable_id <- function(expires = NULL, id = NULL) {
id <- id %||% uuid()
expires <- if (is.null(expires)) {
"null"
} else {
if (is.numeric(expires)) {
expires <- format(expires)
} else {
stop(
"`expires` must be a numeric number of days for retention of stored values",
call. = FALSE
)
}
}
htmltools::htmlDependency(
name = "xaringanExtra-editable-id",
version = "0.2.6",
src = ".",
head = format(htmltools::tags$script(
type = "application/json",
id = "xaringanExtra-editable-docid",
sprintf('{"id":"%s","expires":%s}', id, expires)
)),
all_files = FALSE
)
}
uuid <- function() {
# Create a unique id for this document, ensure that it's a valid HTML ID
x <- uuid::UUIDgenerate()
if (!substr(x, 1, 1) %in% letters) substr(x, 1, 1) <- "x"
gsub("-", "", x)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/editable.R |
#' Fit Slides to the Screen
#'
#' This extension resizes the slides to match the browser window height and
#' width. In other words, the slides are maximized to match the screen size.
#' The primary use case for this extension is for when you want to show your
#' slides in split screen, for example when demonstrating code in RStudio or
#' another window. To enable fit-to-screen, press **Alt**/**Option** + **F** during the
#' slideshow. To disable, reload the slides.
#'
#' @examples
#' use_fit_screen()
#'
#' @return An`htmltools::tagList()` with the fit-to-screen dependency, or an
#' [htmltools::htmlDependency()].
#'
#' @section Usage: To enable fit-to-screen, add the following code chunk to your
#' slides:
#'
#' ````markdown
#' ```{r xaringan-fit-screen, echo=FALSE}
#' xaringanExtra::use_fit_screen()
#' ```
#' ````
#'
#' And then press **Alt**/**Option** + **F** at any point during your slide show to
#' enable the extension.
#' @name fit_screen
NULL
#' @describeIn fit_screen Use the fit-to-screen extension in your xaringan slides.
#' @export
use_fit_screen <- function() {
htmltools::tagList(
html_dependency_fit_screen()
)
}
#' @describeIn fit_screen Returns an [htmltools::htmlDependency()] with the fit
#' screen dependencies. Most users will want to use `use_fit_screen()`.
#' @export
html_dependency_fit_screen <- function() {
htmltools::htmlDependency(
name = "xaringanExtra_fit-screen",
version = "0.2.6",
package = "xaringanExtra",
src = "fit-screen",
script = "fit-screen.js",
all_files = FALSE
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/fit-screen.R |
#' FreezeFrame
#'
#' @description
#' FreezeFrame starts any gifs on a slide when you turn to that slide. This
#' helps This helps alleviate the awkward pause that can happen when you turn to
#' a slide with a gif that has already started and you have to wait until it
#' loops back around. You can also directly click on the gif to stop or start
#' it.
#'
#' @section Usage: To add FreezeFrame to your `xaringan` presentation,
#' add the following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringanExtra-freezeframe, echo=FALSE}
#' xaringanExtra::use_freezeframe()
#' ```
#' ````
#' @examples
#' use_freezeframe()
#'
#' @param selector The selector used to search for `.gifs` to freeze.
#' @param trigger The trigger event to start animation for non-touch devices.
#' One of `"click"` (default), `"hover"` or `"none"`.
#' @param overlay Whether or not to display a play icon on top of the paused
#' image, default: `FALSE`.
#' @param responsive Whether or not to make the image responsive (100% width),
#' default: `TRUE`.
#' @param warnings Whether or not to issue warnings in the browser console if
#' an image doesn't appear to be a gif.
#'
#' @return An `htmltools::tagList()` with the FreezeFrame dependencies, or an
#' [htmltools::htmlDependency()].
#'
#' @references <http://ctrl-freaks.github.io/freezeframe.js/>,
#' <https://github.com/ctrl-freaks/freezeframe.js/>
#' @name freezeframe
NULL
#' @describeIn freezeframe Adds FreezeFrame to your xaringan slides.
#' @export
use_freezeframe <- function(
selector = 'img[src$="gif"]',
trigger = c("click", "hover", "none"),
overlay = FALSE,
responsive = TRUE,
warnings = TRUE
) {
htmltools::tagList(
html_dependency_freezeframe(),
html_dependency_freezeframe_init(selector, trigger, overlay, responsive, warnings)
)
}
#' @describeIn freezeframe Returns an [htmltools::htmlDependency()] with the
#' FreezeFrame dependencies for use in xaringan and R Markdown documents.
#' Most users will want to use `use_freezeframe()` instead.
#'
#' @export
html_dependency_freezeframe <- function() {
htmltools::htmlDependency(
name = "freezeframe",
version = "5.0.2",
package = "xaringanExtra",
src = "jslib/freezeframe",
script = "freezeframe.min.js",
all_files = FALSE
)
}
html_dependency_freezeframe_init <- function(
selector = 'img[src$="gif"]',
trigger = c("click", "hover", "none"),
overlay = FALSE,
responsive = TRUE,
warnings = TRUE
) {
htmltools::htmlDependency(
name = "xaringanExtra-freezeframe",
version = "0.0.1",
package = "xaringanExtra",
src = "freezeframe",
script = "freezeframe-init.js",
head = freezeframe_options(selector, trigger, overlay, responsive, warnings),
all_files = FALSE
)
}
freezeframe_options <- function(
selector = 'img[src$="gif"]',
trigger = c("click", "hover", "none"),
overlay = FALSE,
responsive = TRUE,
warnings = TRUE
) {
trigger <- match.arg(trigger)
if (identical(trigger, "none")) trigger <- FALSE
stopifnot(
"selector must be a character" = is.character(selector),
"selector must be non-missing" = length(selector) > 0 && !is.na(selector),
"overlay must be boolean" = is.logical(overlay),
"responsive must be boolean" = is.logical(responsive),
"warnings must be boolean" = is.logical(warnings)
)
opts <- jsonlite::toJSON(
list(
selector = paste(selector, collapse = ", "),
trigger = trigger,
overlay = overlay,
responsive = responsive,
warnings = warnings
),
auto_unbox = TRUE
)
script <- htmltools::tags$script(
id = "xaringanExtra-freezeframe-options",
type = "application/json",
htmltools::HTML(opts)
)
format(script)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/freezeframe.R |
#' Panelset
#'
#' A panelset designed for showing off code, but useful for anything really.
#'
#' @return An `htmltools::tagList()` with the panelset dependencies, or an
#' [htmltools::htmlDependency()].
#' @section Usage: To add panelset to your xaringan presentation, add the
#' following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringan-panelset, echo=FALSE}
#' xaringanExtra::use_panelset()
#' ```
#'
#' .panelset[
#' .panel[.panel-name[app.R]
#'
#' ```r
#' hist(runif(100))
#' ```
#' ]
#'
#' .panel[.panel-name[About]
#'
#' Take a look at the R code in that other panel.
#' ]
#' ]
#' ````
#'
#' @includeRmd man/fragments/panelset_sideways.Rmd
#'
#' @includeRmd man/fragments/panelset_custom-styles.Rmd
#'
#' @includeRmd man/fragments/panelset_other-rmd.Rmd
#'
#' @includeRmd man/fragments/panelset_chunks.Rmd
#'
#' @examples
#' use_panelset()
#'
#' @name panelset
NULL
#' @describeIn panelset Adds panelset to your xaringan slides.
#' @param in_xaringan Set to `TRUE` if rendering in xaringan slides or `FALSE`
#' if using panelset elsewhere. This determines the style of knitr hook that
#' is registered to enable the `panelset` chunk option.
#' @export
use_panelset <- function(in_xaringan = NULL) {
register_panelset_knitr_hooks(in_xaringan)
htmltools::tagList(
html_dependency_panelset()
)
}
#' @describeIn panelset Style the panelset. Returns an \pkg{htmltools} `<style>`
#' tag.
#' @param foreground The text color of a non-active panel tab, default is
#' `currentColor`.
#' @param active_foreground The text color of an active, as in selected, panel
#' tab. Default is `currentColor`.
#' @param hover_foreground The text color of a hovered panel tab. Default is
#' `currentColor`.
#' @param tabs_border_bottom The border color between the tabs and content.
#' Default is `#ddd`.
#' @param tabs_sideways_max_width The maximum width of the tabs in sideways
#' mode. The default value is `25%`. A value between 25% and 33% is
#' recommended. The tabs can only ever be at most 50% of the container width.
#' @param inactive_opacity The opacity of inactive panel tabs, default is `0.5`.
#' @param font_family The font family to be used for the panel tabs text.
#' Default is a monospace system font stack.
#' @param background,active_background,hover_background Background colors for
#' panel tabs; in-active tabs, active tab, hovered tab. The default values are
#' all `unset`.
#' @param active_border_color,hover_border_color The color of the top border of
#' a tab when it is active or the color of the bottom border of a tab when it
#' is hovered or focused. Defaults are `currentColor`.
#' @param selector The CSS selector used to choose which panelset is being
#' styled. In most cases, you can use the default selector and style all
#' panelsets on the page.
#' @export
style_panelset_tabs <- function(
foreground = NULL,
background = NULL,
...,
active_foreground = NULL,
active_background = NULL,
active_border_color = NULL,
hover_background = NULL,
hover_foreground = NULL,
hover_border_color = NULL,
tabs_border_bottom = NULL,
tabs_sideways_max_width = NULL,
inactive_opacity = NULL,
font_family = NULL,
selector = ".panelset"
) {
if (length(list(...))) {
warning(
"The arguments to `syle_panelset()` changed in xaringanExtra 0.1.0. ",
"Please refer to the documentation to update your slides.",
immediate. = TRUE
)
}
fn_args <- setdiff(names(formals()), c("...", "selector"))
names(fn_args) <- fn_args
args <- lapply(fn_args, function(x) get(x))
args <- args[vapply(args, function(x) !is.null(x), TRUE)]
if (!length(args)) {
return(invisible(NULL))
}
names(args) <- panelset_match_vars(names(args))
if ("--panel-tab-font-family" %in% names(args) &&
identical(args["--panel-tab-font-family"], "monospace")) {
args["--panel-tab-font-family"] <- "Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace"
}
style <- ""
for (var in names(args)) {
style <- paste0(style, var, ": ", args[var], ";")
}
style <- paste0("<style>", selector, "{", style, "}</style>")
htmltools::HTML(style)
}
#' @describeIn panelset Deprecated, renamed `style_panelset_tabs()`.
#' @param ... Ignored or passed from `style_panelset()` to `style_panelset_tabs()`.
#' @export
style_panelset <- function(...) {
.Deprecated("style_panelset_tabs")
style_panelset_tabs(...)
}
panelset_match_vars <- function(x = NULL) {
vars <- c(
foreground = "--panel-tab-foreground",
background = "--panel-tab-background",
active_foreground = "--panel-tab-active-foreground",
active_background = "--panel-tab-active-background",
active_border_color = "--panel-tab-active-border-color",
hover_background = "--panel-tab-hover-background",
hover_foreground = "--panel-tab-hover-foreground",
hover_border_color = "--panel-tab-hover-border-color",
tabs_border_bottom = "--panel-tabs-border-bottom",
inactive_opacity = "--panel-tab-inactive-opacity",
font_family = "--panel-tab-font-family",
tabs_sideways_max_width = "--panel-tabs-sideways-max-width"
)
if (is.null(x)) {
return(vars)
}
vars[x]
}
#' @describeIn panelset Returns an [htmltools::htmlDependency()] with the tile
#' view dependencies. Most users will want to use `use_panelset()`.
#' @export
html_dependency_panelset <- function() {
htmltools::htmlDependency(
name = "panelset",
version = "0.2.6",
package = "xaringanExtra",
src = "panelset",
script = "panelset.js",
stylesheet = "panelset.css"
)
}
# package env to hold original knitr hooks
.hooks <- new.env(parent = emptyenv())
register_panelset_knitr_hooks <- function(in_xaringan = NULL) {
if (!knitr::is_html_output()) {
return()
}
.hooks$source <- knitr::knit_hooks$get("source")
.hooks$output <- knitr::knit_hooks$get("output")
in_xaringan <- output_is_xaringan(in_xaringan)
# ::: start-code-panel <- panelset source hook
# source code <- original source hook
# ::: end-code-panel <- panelset source hook
# ::: start-output-panel <- panelset source hook
# output
# ::: end-output-panel <- panelset knit hook, !before
knitr::knit_hooks$set(source = function(x, options) {
if (is.null(options$panelset) || identical(options$panelset, FALSE)) {
return(.hooks$source(x, options))
}
if (isTRUE(in_xaringan)) {
panelset_chunk_before_xaringan(x, options)
} else {
panelset_chunk_before_html(x, options)
}
})
knitr::knit_hooks$set(panelset = function(before, options, ...) {
if (before) {
return()
}
if (isTRUE(in_xaringan)) "\n\n]" else "\n\n</div>"
})
knitr::opts_hooks$set(panelset = function(options) {
# panelset chunks ignore global options and default to results="hold"
# but can be overwritten by the local chunk options if declared explicitly
chunk_opts <- attr(knitr::knit_code$get(options$label), "chunk_opts")
options$results <- chunk_opts$results %||% "hold"
options
})
}
panelset_source_opts <- function(opt) {
if (is.null(opt)) {
return(NULL)
}
default <- c(source = "Code", output = "Output")
opt <- unlist(opt)
if (isTRUE(opt) || length(opt) < 1 || !is.character(opt)) {
return(default)
}
if (!is.null(names(opt))) {
opt <- opt[intersect(names(default), names(opt))]
}
if (length(opt) > 2) {
warning("`panelset` chunk option expects at most two values")
opt <- opt[1:2]
}
if (is.null(names(opt))) {
names(opt) <- names(default)[seq_along(opt)]
}
if (!length(opt) == 2) {
opt <- c(
opt[intersect(names(default), names(opt))],
default[setdiff(names(default), names(opt))]
)
}
opt[names(default)]
}
panelset_chunk_before_xaringan <- function(x, options) {
panel_names <- panelset_source_opts(options$panelset)
paste(
sprintf(".panel[.panel-name[%s]", panel_names["source"]),
"",
.hooks$source(x, options),
"\n]\n",
sprintf(".panel[.panel-name[%s]", panel_names["output"]),
"\n",
sep = "\n"
)
}
panelset_chunk_before_html <- function(x, options) {
panel_names <- panelset_source_opts(options$panelset)
paste(
'<div class="panel">',
sprintf('<div class="panel-name">%s</div>', panel_names["source"]),
"",
.hooks$source(x, options),
"\n</div>\n",
'<div class="panel">',
sprintf('<div class="panel-name">%s</div>', panel_names["output"]),
"\n",
sep = "\n"
)
}
output_is_xaringan <- function(in_xaringan) {
if (isTRUE(in_xaringan)) {
return(TRUE)
}
# This will probably work in most cases but I'm not sure how else to be
# certain that the document currently being rendered is xaringan slides...
has_xaringan_page_opt() && is_moon_reader_output()
}
has_xaringan_page_opt <- function() {
!is.null(getOption("xaringan.page_number.offset", NULL))
}
is_moon_reader_output <- function() {
if (!requireNamespace("rmarkdown", quietly = TRUE)) {
# Not sure how we'd get here but just in case, skip this check
return(TRUE)
}
grepl(
"moon_reader",
rmarkdown::all_output_formats(knitr::current_input())
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/panelset.R |
#' Add an animated progress bar
#'
#' Adds an animated progress bar to all slides.
#'
#' @param color A valid CSS color to be used as the color of the progress bar.
#' @param location One of `"top"` or `"bottom"`.
#' @param height A valid CSS unit specifying the height of the progress bar.
#'
#' @return An `htmltools::tagList()` with the HTML dependencies required for
#' **progress bar**.
#'
#' @examples
#' xaringanExtra::use_progress_bar("red", "top", "0.25em")
#'
#' @export
use_progress_bar <- function(
color = "red",
location = c("top", "bottom"),
height = "0.25em"
) {
location <- match.arg(location)
height <- htmltools::validateCssUnit(height)
htmltools::tagList(
htmltools::tags$style(htmltools::HTML(progress_bar_css(color, location, height))),
htmltools::htmlDependency(
name = "xaringanExtra-progressBar",
version = "0.0.1",
package = "xaringanExtra",
src = "progress-bar",
script = "progress-bar.js",
all_files = FALSE
)
)
}
progress_bar_css <- function(color = "red", location = "top", height = "10px") {
css <- '.xe__progress-bar__container {
%s:0;
opacity: 1;
position:absolute;
right:0;
left: 0;
}
.xe__progress-bar {
height: %s;
background-color: %s;
width: calc(var(--slide-current) / var(--slide-total) * 100%%);
}
.remark-visible .xe__progress-bar {
animation: xe__progress-bar__wipe 200ms forwards;
animation-timing-function: cubic-bezier(.86,0,.07,1);
}
@keyframes xe__progress-bar__wipe {
0%% { width: calc(var(--slide-previous) / var(--slide-total) * 100%%); }
100%% { width: calc(var(--slide-current) / var(--slide-total) * 100%%); }
}'
sprintf(css, location, height, color)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/progress-bar.R |
#' Scribble
#'
#' @description
#' Scribble lets you draw on your \pkg{xaringan} slides. Click the pencil icon
#' to begin drawing. Use the eraser to remove lines from your drawing, or the
#' trash to clear the entire canvas. Note that in order to minimize confusion,
#' you will not be able to navigate slides while in draw or erase mode.
#'
#' You may toggle the visibility of the scribble toolbox by pressing `S` at
#' any time. Your drawings will persist when changing slides. You may save a
#' permanent copy of the slides with the markup by printing your presentation
#' (e.g. using Chrome > File > Print).
#'
#' @section Usage: To add scribble to your `xaringan` presentation,
#' add the following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringan-scribble, echo=FALSE}
#' xaringanExtra::use_scribble()
#' ```
#' ````
#'
#' @examples
#' use_scribble()
#'
#' @param pen_color Initial pen color (default is `"#FF0000` (red)). Must be a
#' hexadecimal color, e.g. `#000` or `#4232ea`.
#' @param pen_size Pen size (default is 3).
#' @param eraser_size Eraser size (default is `pen_size * 10`).
#' @param palette A selection of up to 10 colors that become available when
#' drawing is active via the keys `0` through `9`. Press the number keys of
#' 0-9 to quickly active each of the palette colors.
#'
#' @return An `htmltools::tagList()` with the scribble dependencies, or an
#' [htmltools::htmlDependency()].
#'
#' @name scribble
NULL
#' @describeIn scribble Adds scribble to your xaringan slides.
#' @export
use_scribble <- function(
pen_color = "#FF0000",
pen_size = 3,
eraser_size = pen_size * 10,
palette = NULL
) {
htmltools::tagList(
html_dependency_fabricjs(),
html_dependency_scribble(
pen_color,
pen_size,
eraser_size,
palette
)
)
}
#' @describeIn scribble Returns an [htmltools::htmlDependency()] with the
#' `fabric.js` dependencies for use in xaringan and R Markdown documents.
#' Most users will want to use `use_scribble()` instead.
#'
#' @param minimized Use the minimized `fabric.js` dependency?
#' @export
html_dependency_fabricjs <- function(minimized = TRUE) {
htmltools::htmlDependency(
name = "fabric",
version = "4.3.1",
package = "xaringanExtra",
src = c(
file = "jslib/fabric",
href = "https://unpkg.com/[email protected]/dist"
),
script = if (minimized) "fabric.min.js" else "fabric.js",
all_files = FALSE
)
}
#' @describeIn scribble Returns an [htmltools::htmlDependency()] with the
#' scribble dependencies for use in xaringan and R Markdown documents. Most
#' users will want to use `use_scribble()` instead.
#'
#' @export
html_dependency_scribble <- function(
pen_color,
pen_size,
eraser_size,
palette = NULL
) {
htmltools::htmlDependency(
name = "xaringanExtra-scribble",
version = "0.0.1",
package = "xaringanExtra",
src = "scribble",
script = "scribble.js",
stylesheet = "scribble.css",
head = init_scribble(pen_color, pen_size, eraser_size, palette),
all_files = FALSE
)
}
init_scribble <- function(
pen_color = "#FF0000",
pen_size = 3,
eraser_size = pen_size * 10,
palette = NULL
) {
# Current we expect one color, we may lift this restriction in the future
stopifnot(
"single pen color" = length(pen_color) == 1,
"pen_color must be character" = is.character(pen_color),
"pen_color must be a hexadecimal color" = all(is_hex_color(pen_color))
)
stopifnot(is.numeric(pen_size))
stopifnot(is.numeric(eraser_size))
palette <- palette %||% list()
if (length(palette) > 10) {
warning("The scribble easy-access palette accepts at most 10 colors.")
palette <- palette[1:10]
}
opts <- list(
pen_color = pen_color,
pen_size = jsonlite::unbox(pen_size),
eraser_size = jsonlite::unbox(eraser_size),
palette = palette
)
opts <- jsonlite::toJSON(opts)
sprintf(
paste0(
"<script>document.addEventListener('DOMContentLoaded', function() {",
" window.xeScribble = new Scribble(%s) })</script>"
),
opts
)
}
is_hex_color <- function(x) {
x <- trimws(x)
grepl("^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$", x)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/scribble.R |
#' Search
#'
#' Search gives you a way to quickly search for text on slides.
#'
#' @return An `htmltools::tagList()` with the search dependencies, or an
#' [htmltools::htmlDependency()].
#' @section Usage: To add search to your xaringan presentation, add the
#' following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringan-search, echo=FALSE}
#' xaringanExtra::use_search()
#' ```
#' ````
#'
#' @examples
#' use_search()
#'
#' @references <https://github.com/arestivo/remark.search>
#' @author Original implementation by André Restivo
#' @name search
NULL
#' @describeIn search Adds search to your xaringan slides.
#' @export
use_search <- function(
position = c("bottom-left", "bottom-right", "top-left", "top-right"),
case_sensitive = FALSE,
show_icon = FALSE,
auto_search = TRUE
) {
htmltools::tagList(
html_dependency_markjs(),
html_dependency_search(position, case_sensitive, show_icon, auto_search)
)
}
#' @describeIn search Returns an [htmltools::htmlDependency()] with the search
#' dependencies. Most users will want to use `use_search()`.
#'
#' @param position Where to place the search box.
#' @param case_sensitive If `FALSE`, ignores case of search and text.
#' @param show_icon Show the icon to open or close the search?
#' @param auto_search Search on each keystroke (`TRUE`) or on enter (`FALSE`)?
#'
#' @export
html_dependency_search <- function(
position = c("bottom-left", "bottom-right", "top-left", "top-right"),
case_sensitive = FALSE,
show_icon = FALSE,
auto_search = TRUE
) {
htmltools::htmlDependency(
name = "xaringanExtra-search",
version = "0.0.1",
package = "xaringanExtra",
src = "search",
script = "search.js",
stylesheet = "search.css",
head = init_search(position, case_sensitive, show_icon, auto_search),
all_files = FALSE
)
}
#' @describeIn search Style the search input.
#'
#' @param icon_fill Color of search icon
#' @param input_background Color of search input box background
#' @param input_foreground Color of text in search input box
#' @param input_border Border style of search input box
#' @param match_background Color of match background (not current)
#' @param match_foreground Color of match text (not current)
#' @param match_current_background Color of current match background
#' @param match_current_foreground Color of current match text
#' @param selector CSS selector specifying which search bar to update (for
#' advanced or unusual uses only)
#'
#' @export
style_search <- function(
icon_fill = "rgba(128, 128, 128, 0.5)",
input_background = "rgb(204, 204, 204)",
input_foreground = "black",
input_border = "1px solid rgb(249, 38, 114)",
match_background = "rgb(38, 220, 249)",
match_foreground = "black",
match_current_background = "rgb(38, 249, 68)",
match_current_foreground = "black",
selector = ".search"
) {
css <- sprintf(
"
%s {
--search-icon-fill: %s;
--search-input-background: %s;
--search-input-foreground: %s;
--search-input-border: %s;
--search-match-background: %s;
--search-match-foreground: %s;
--search-match-current-background: %s;
--search-match-current-foreground: %s;
}",
selector,
icon_fill,
input_background,
input_foreground,
input_border,
match_background,
match_foreground,
match_current_background,
match_current_foreground
)
htmltools::tags$style(htmltools::HTML(css))
}
init_search <- function(
position = c("bottom-left", "bottom-right", "top-left", "top-right"),
case_sensitive = FALSE,
show_icon = FALSE,
auto_search = TRUE
) {
position <- match.arg(position)
stopifnot(is.logical(case_sensitive), is.logical(show_icon), is.logical(auto_search))
opts <- jsonlite::toJSON(
list(
position = position,
caseSensitive = case_sensitive,
showIcon = show_icon,
autoSearch = auto_search
),
auto_unbox = TRUE,
pretty = FALSE
)
sprintf(
"<script>window.addEventListener('load', function() { window.xeSearch = new RemarkSearch(%s) })</script>",
opts
)
}
html_dependency_markjs <- function() {
htmltools::htmlDependency(
name = "mark.js",
version = "8.11.1",
package = "xaringanExtra",
src = "jslib/markjs",
script = "mark.min.js",
all_files = FALSE
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/search.R |
#' Share or Embed xaringan Slides
#'
#' The _share again_ extension helps you share your xaringan slides. Adding the
#' extension to your slides with `use_share_again()` enables a "share" bar that
#' only appears when your slides are embedded in a web page in an `<iframe>`. To
#' embed your presentation in another page, like a blogdown post or a R Markdown
#' based site, use `embed_xaringan()`. This function adds your slides in a
#' responsive aspect ratio container that seamlessly includes your slides in
#' the page. Finally, for perfect looking slides, use `style_share_again()` to
#' style the share bar to match your slides' aesthetic. You can also use this
#' function to enable or disable specific social media sites and platforms from
#' the share menu.
#'
#' @examples
#' # In your slides call
#' use_share_again()
#'
#' # In the document where you want to embed the slides call
#' embed_xaringan("https://slides.yihui.org/xaringan/")
#'
#' @seealso [embed_xaringan()]
#' @name share_again
NULL
#' @describeIn share_again Add the _share again_ bar to your slides (only shown
#' when embedded in an `<iframe>`)
#'
#' @return An `htmltools::tagList()` with the HTML dependencies required for
#' **share again**.
#'
#' @export
use_share_again <- function() {
htmltools::tagList(
html_dependency_clipboardjs(),
html_dependency_shareon(),
html_dependency_shareagain()
)
}
#' @describeIn share_again Style the _share again_ bar to match your slides, or
#' choose the social media sites included in the share menu
#'
#' @param foreground The foreground color of the buttons and text in the share bar
#' @param background The background color of the share bar
#' @param share_buttons A vector of social media platforms to be included in the
#' share menu of the share bar. You can include `"all"` sites or `"none"` of
#' buttons, and if either are included in `share_buttons`, then the rest of
#' the vector is ignored. (And `"all"` takes precedence over `"none"`.) The
#' _copy link_ option is always included.
#'
#' @export
style_share_again <- function(
foreground = "rgb(255, 255, 255)",
background = "rgba(0, 0, 0, 0.5)",
share_buttons = c("all", "none", "twitter", "facebook", "linkedin", "pinterest", "pocket", "reddit")
) {
social_sites <- share_button_social_options()
share_buttons <- match.arg(share_buttons, several.ok = TRUE)
if ("all" %in% share_buttons && length(share_buttons) > 1) {
share_buttons <- "all"
}
if ("none" %in% share_buttons && length(share_buttons) > 1) {
share_buttons <- "none"
}
share_buttons_hide <- if (identical(share_buttons, "none")) {
social_sites
} else if (!identical(share_buttons, "all")) {
setdiff(social_sites, share_buttons)
}
vars_buttons <- if (!is.null(share_buttons_hide) && length(share_buttons_hide)) {
sprintf("--shareagain-%s: none;", share_buttons_hide)
}
css_vars <- c(
if (!is.null(foreground)) sprintf("--shareagain-foreground: %s;", foreground),
if (!is.null(background)) sprintf("--shareagain-background: %s;", background),
vars_buttons
)
if (!length(css_vars)) {
return()
}
css_vars <- paste(".shareagain-bar {", paste(css_vars, collapse = "\n"), "}", sep = "\n")
htmltools::tags$style(css_vars)
}
share_button_social_options <- function() {
full_share_options <- eval(formals("style_share_again")[["share_buttons"]])
setdiff(full_share_options, c("all", "none"))
}
#' Embed a xaringan presentation in a web page
#'
#' Embed xaringan slides in any HTML web page, such as a blogdown page or an
#' R Markdown website. The presentation is embedded in a responsive aspect ratio
#' container for seamless integration with your web page. This feature works
#' best when combined with [use_share_again()], but `embed_xaringan()` can be
#' used for any xaringan presentation.
#'
#' @examples
#' # In your slides call
#' use_share_again()
#'
#' @param url The URL or path to the presentation to embed.
#' @param ratio The ratio of the presentation, either as `"width:height"` or
#' `width/height`, e.g. `"16:9"` or `1.7777`.
#' @param border The border style of the embedded `<iframe>`. For no border, use
#' `"none"`.
#' @param max_width The max width of the `<iframe>`, in a valid CSS units.
#' @param margin The margin placed around the embedded `<iframe>`.
#' @param style Additional CSS `style` property value pairs, e.g.
#' `c("padding-left: 1em", "padding-right: 1em")`.
#'
#' @return An `htmltools::tagList()` with the HTML dependencies required for
#' **share again**.
#'
#' @seealso [use_share_again()]
#' @export
embed_xaringan <- function(
url,
ratio = "16:9",
border = "2px solid currentColor",
max_width = NULL,
margin = "1em auto",
style = NULL
) {
ratio <- parse_ratio(ratio)
style <- paste(style, collapse = ";")
style <- sprintf("border:%s;%s", border, style)
style <- gsub(";;", ";", style) # just in case
parent_style <- sprintf("min-width:300px;margin:%s;", margin)
if (!is.null(max_width)) {
parent_style <- sprintf(
"%smax-width:%s;",
parent_style,
htmltools::validateCssUnit(max_width)
)
}
htmltools::tagList(
htmltools::div(
class = "shareagain",
style = parent_style,
`data-exeternal` = "1",
htmltools::tags$iframe(
src = url,
width = unname(ratio["width"]),
height = unname(ratio["height"]),
style = style,
loading = "lazy",
allowfullscreen = NA
),
htmltools::tags$script(htmltools::HTML("fitvids('.shareagain', {players: 'iframe'});")),
html_dependency_fitvids()
)
)
}
parse_ratio <- function(x) {
x <- strsplit(as.character(x), ":")[[1]]
x <- suppressWarnings(as.numeric(x))
x <- x[!is.na(x)]
if (!length(x) %in% 1:2) {
stop("ratio must be \"w:h\" or a single number representing w/h")
}
if (length(x) == 1) {
c(width = x, height = 1) * 300
} else {
c(width = x[1], height = x[2]) * 100
}
}
html_dependency_shareagain <- function() {
htmltools::htmlDependency(
name = "xaringanExtra-shareagain",
version = "0.2.6",
package = "xaringanExtra",
src = "share-again",
script = "shareagain.js",
stylesheet = "shareagain.css",
all_files = FALSE
)
}
html_dependency_fitvids <- function() {
# https://github.com/rosszurowski/fitvids/
htmltools::htmlDependency(
name = "fitvids",
version = "2.1.1",
package = "xaringanExtra",
src = c(
file = "jslib/fitvids",
href = "https://unpkg.com/[email protected]/dist/"
),
script = "fitvids.min.js",
all_files = FALSE
)
}
html_dependency_shareon <- function() {
# https://github.com/NickKaramoff/shareon
# https://shareon.js.org/
htmltools::htmlDependency(
name = "shareon",
version = "1.4.1",
package = "xaringanExtra",
src = c(
file = "jslib/shareon",
href = "https://unpkg.com/[email protected]/dist/"
),
script = "shareon.min.js",
stylesheet = "shareon.min.css",
all_files = FALSE
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/share_again.R |
#' Slide Tone
#'
#' Slide tone plays a subtle sound when you change slides.The tones increase in
#' pitch for each slide from a low C to a high C note. The tone pitch stays the
#' same for incremental slides.
#'
#' @section Usage: To add slide tone to your xaringan presentation, add the
#' following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringan-slide-tone, echo=FALSE}
#' xaringanExtra::use_slide_tone()
#' ```
#' ````
#' @examples
#' use_slide_tone()
#'
#' @return An `htmltools::tagList()` with the slide tone dependencies, or an
#' [htmltools::htmlDependency].
#'
#' @references [tone.js](https://tonejs.github.io/)
#' @name slide_tone
NULL
#' @describeIn slide_tone Adds slide tone to your xaringan slides.
#' @export
use_slide_tone <- function() {
htmltools::tagList(
html_dependency_slide_tone()
)
}
#' @describeIn slide_tone Returns an [htmltools::htmlDependency] with the tile
#' view dependencies. Most users will want to use `use_slide_tone()`.
#' @export
html_dependency_slide_tone <- function() {
htmltools::tagList(
htmltools::htmlDependency(
name = "tone",
version = "13.8.34",
package = "xaringanExtra",
src = "jslib/tone",
script = "Tone.js",
all_files = FALSE
),
htmltools::htmlDependency(
name = "slide-tone",
version = "0.2.6",
package = "xaringanExtra",
src = "slide-tone",
script = "slide-tone.js"
)
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/slide-tone.R |
#' Add Extra CSS Styles
#'
#' Adds CSS extras to your slides. You can select which extras you wish to add
#' to your slides.
#'
#' @examples
#' use_extra_styles()
#'
#' @name extra_styles
NULL
#' @describeIn extra_styles Add the extra CSS styles to your slides
#' @param hover_code_line Adds a hover effect for code chunks in your slides.
#' Adds a floating pointer to the hovered line and makes the line bold.
#' @param mute_unhighlighted_code On code chunks with highlights (added with
#' line-ending `#<<` comments or starting with `*`), non-highlighted lines
#' are muted and the highlighted line is full opacity.
#' @param bundle_id Make the CSS bundle unique. Use this if your slides share
#' a common resource directory and you want to include different CSS extras
#' in different slides.
#'
#' @return An [htmltools::htmlDependency()] with the selected additional styles.
#' @export
use_extra_styles <- function(
hover_code_line = TRUE,
mute_unhighlighted_code = TRUE,
bundle_id = NULL
) {
dep <- html_dependency_extra_styles(
hover_code_line,
mute_unhighlighted_code,
bundle_id
)
if (is.null(dep)) {
return(invisible())
}
htmltools::tagList(dep)
}
#' @describeIn extra_styles Returns an [htmltools::htmlDependency()] with the
#' extra styles dependencies. Most users will want to use `use_extra_styles()`.
#' @export
html_dependency_extra_styles <- function(
hover_code_line = TRUE,
mute_unhighlighted_code = TRUE,
bundle_id = NULL
) {
if (!any(c(hover_code_line, mute_unhighlighted_code))) {
return(invisible())
}
css_file <- file.path(tempdir(), "xaringanExtra-extra-styles.css")
if (file.exists(css_file)) unlink(css_file)
add_to_css <- function(...) {
new_css <- readLines(xe_file("extra-styles", ...), warn = FALSE)
cat(new_css, file = css_file, sep = "\n", append = TRUE)
}
if (isTRUE(hover_code_line)) {
add_to_css("code-line-hover.css")
}
if (isTRUE(mute_unhighlighted_code)) {
add_to_css("code-mute-unhighlighted.css")
}
name <- paste0("xaringanExtra-extra-styles", if (!is.null(bundle_id)) {
paste0(
"_",
bundle_id
)
})
htmltools::htmlDependency(
name = name,
version = "0.2.6",
src = dirname(css_file),
stylesheet = basename(css_file),
all_files = FALSE
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/styles.R |
#' Tachyons
#'
#' Tachyons is a collection of CSS utility classes that works beautifully with
#' \pkg{xaringan} presentations using the `remarkjs`` class syntax.
#'
#' @section Usage: To add tachyons to your xaringan presentation, add the
#' following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringan-tachyons, echo=FALSE}
#' xaringanExtra::use_tachyons()
#' ```
#' ````
#'
#' Tachyons provides small, single-purpose CSS classes that are easily composed
#' to achieve larger functionality and styles. In the [remarkjs content classes
#' syntax](https://github.com/gnab/remark/wiki/Markdown#content-classes), you
#' can compose classes by chaining them together. For example, the following
#' markdown produces a box with a washed green background (`.bg-washed-green`),
#' a dark green border (`.b--dark-green`) on all sides (`.ba`) with line width
#' 2 (`.bw2`) and border radius (`.br3`). The box has a shadow (`.shadow-5`)
#' and medium-large horizontal padding (`.ph4`) with a large top margin
#' (`.mt5`).
#'
#' ```markdown
#' .bg-washed-green.b--dark-green.ba.bw2.br3.shadow-5.ph4.mt5[
#' The only way to write good code is to write tons of bad code first.
#' Feeling shame about bad code stops you from getting to good code
#'
#' .tr[
#' — Hadley Wickham
#' ]]
#' ```
#' @examples
#' use_tachyons()
#'
#' @references [tachyons](http://tachyons.io/),
#' [Tachyons Cheat Sheet](https://roperzh.github.io/tachyons-cheatsheet/)
#' @return An `htmltools::tagList()` with the tachyons dependencies, or an
#' [htmltools::htmlDependency()].
#' @name tachyons
NULL
#' @describeIn tachyons Adds tachyons to your xaringan slides.
#' @param minified Use the minified Tachyons css file? Default is `TRUE`.
#' @export
use_tachyons <- function(minified = TRUE) {
htmltools::tagList(
html_dependency_tachyons(minified)
)
}
#' @describeIn tachyons Returns an [htmltools::htmlDependency()] with the tile
#' view dependencies. Most users will want to use `use_tachyons()`.
#' @export
html_dependency_tachyons <- function(minified = TRUE) {
tachyons_version <- "4.12.0"
htmltools::htmlDependency(
name = "tachyons",
version = tachyons_version,
package = "xaringanExtra",
src = "jslib/tachyons",
stylesheet = paste0("tachyons", if (minified) ".min", ".css"),
all_files = FALSE
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/tachyons.R |
#' Tile View
#'
#' Tile view gives you a way to quickly jump between slides. Just press **O** at
#' any point in your slideshow and the tile view appears. Click on a slide to
#' jump to the slide, or press **O** to exit tile view.
#'
#' @section Usage: To add tile view to your xaringan presentation, add the
#' following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringan-tile-view, echo=FALSE}
#' xaringanExtra::use_tile_view()
#' ```
#' ````
#' @examples
#' use_tile_view()
#'
#' @return An `htmltools::tagList()` with the tile view dependencies, or an
#' [htmltools::htmlDependency()].
#' @name tile_view
NULL
#' @describeIn tile_view Adds tile view to your xaringan slides.
#' @export
use_tile_view <- function() {
htmltools::tagList(
html_dependency_tile_view()
)
}
#' @describeIn tile_view Returns an [htmltools::htmlDependency()] with the tile
#' view dependencies. Most users will want to use `use_tile_view()`.
#' @export
html_dependency_tile_view <- function() {
htmltools::htmlDependency(
name = "tile-view",
version = "0.2.6",
package = "xaringanExtra",
src = "tile-view",
script = "tile-view.js",
stylesheet = "tile-view.css"
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/tile-view.R |
#' Add Logo
#'
#' `use_logo()` adds a logo to all of your slides. You can make the logo a
#' clickable link and choose where on the page it is placed. You can also set
#' which types of slides will not get the logo by default.
#'
#' @return An `htmltools::tagList()` with the Add Logo dependencies, or an
#' [htmltools::htmlDependency()].
#' @section Usage: To add a logo to your xaringan presentation, add the
#' following code chunk to your slides' R Markdown file.
#'
#' ````markdown
#' ```{r xaringan-logo, echo=FALSE}
#' xaringanExtra::use_logo(
#' image_url = "https://raw.githubusercontent.com/rstudio/hex-stickers/master/PNG/xaringan.png"
#' )
#' ```
#' ````
#'
#' See the documentation for `?use_logo` for more options regarding sizing
#' and positioning. You can also make the logo a link using `link_url` and
#' you can hide the logo for a particular slide by using the `hide_logo`
#' slide class.
#'
#' @examples
#' xaringan_logo <- file.path(
#' "https://raw.githubusercontent.com/rstudio/hex-stickers/master",
#' "PNG/xaringan.png"
#' )
#' use_logo(xaringan_logo)
#'
#' @name logo
NULL
#' @describeIn logo Adds logo to your xaringan slides.
#' @param image_url The URL to the image file of your logo. In general, either
#' a full URL or the path to the image relative to your slides file.
#' @param position The position of the logo from the sides of the slide. Use
#' [css_position()] to specify.
#' @param link_url Optional. If provided, your logo becomes a clickable link.
#' @param exclude_class The slide classes that should not receive the logo. By
#' default, the title slide, inverse slides and slides with the `hide_logo`
#' class are excluded.
#' @param width Width in CSS units of the logo
#' @param height Height in CSS units of the logo
#' @export
use_logo <- function(
image_url,
width = "110px",
height = "128px",
position = css_position(top = "1em", right = "1em"),
link_url = NULL,
exclude_class = c("title-slide", "inverse", "hide_logo")
) {
htmltools::div(
htmltools::tags$style(
type = "text/css",
htmltools::HTML(
logo_css(image_url, width, height, position)
)
),
html_dependency_logo(link_url, exclude_class)
)
}
#' Helper to set absolute position of an element.
#'
#' Sets position for an absolutely positioned element. Setting one of top or
#' bottom or one of left or right will "unset" the other. It's probably not a
#' good idea to set both top and bottom or right and left.
#'
#' @param top,right,bottom,left The position of the element in distance from the
#' top, right, bottom, or left edge of it's container element.
#'
#' @return An object of class `css_position` that describes `top`, `right`,
#' `bottom`, and `left` positions.
#'
#' @examples
#' css_position(top = "1em", right = "1em") # top right corner
#' css_position(top = "1em", left = "1em") # top left corner
#' css_position(bottom = 0, right = 0) # bottom right corner
#' @export
css_position <- function(
top = "1em",
right = "1em",
left = NULL,
bottom = NULL
) {
p <- list()
p$top <- if (!is.null(bottom) && missing(top)) NULL else top
p$right <- if (!is.null(left) && missing(right)) NULL else right
p$bottom <- if (!is.null(top) && missing(bottom)) NULL else bottom
p$left <- if (!is.null(right) && missing(left)) NULL else left
class(p) <- c("css_position", class(p))
p
}
is_css_position <- function(x) {
if (inherits(x, "css_position")) {
return(TRUE)
}
x <- x[vapply(x, function(y) !is.null(y), logical(1))]
has_vert <- length(setdiff(c("top", "bottom"), names(x))) <= 1
has_horz <- length(setdiff(c("right", "left"), names(x))) <= 1
has_vert && has_horz
}
#' @describeIn logo Returns an [htmltools::htmlDependency()] with the tile
#' view dependencies. Most users will want to use `use_logo()`.
#' @param inline In [html_dependency_logo()], should the JS and CSS code to
#' create the logo be returned inline (inside the rendered slides) or in
#' separate CSS and JS documents attached as an html dependency? The default
#' is to use inline for \pkg{xaringan} version 0.16 or later.
#' @export
html_dependency_logo <- function(
link_url = NULL,
exclude_class = c("title-slide", "inverse", "hide_logo"),
inline = NULL
) {
inline <- inline %||% xaringan_version("0.16")
logo_code_js <- logo_js(link_url, exclude_class)
ret <- if (inline) {
htmltools::HTML(paste0("<script>", logo_code_js, "</script>"))
} else {
tmpdir <- tempfile("xaringanExtra-add-logo_")
js <- file.path(tmpdir, "logo.js")
dir.create(tmpdir)
cat(logo_code_js, file = js)
htmltools::htmlDependency(
name = "xaringanExtra-logo",
version = "0.2.6",
src = tmpdir,
script = "logo.js"
)
}
htmltools::tagList(ret)
}
logo_css <- function(url, width, height, position) {
if (!is_css_position(position)) {
stop("Please use `css_position()` to specify the position of your logo", call. = FALSE)
}
dirs <- c("top", "right", "left", "bottom")
names(dirs) <- dirs
p <- lapply(dirs, function(pos) {
if (!is.null(position[[pos]])) sprintf("%s:%s;", pos, position[[pos]]) else ""
})
width <- htmltools::validateCssUnit(width)
height <- htmltools::validateCssUnit(height)
sprintf(".xaringan-extra-logo {
width: %s;
height: %s;
z-index: 0;
background-image: url(%s);
background-size: contain;
background-repeat: no-repeat;
position: absolute;
%s%s%s%s
}
", width, height, url, p$top, p$right, p$bottom, p$left)
}
logo_js <- function(link_url, exclude_class = c("title-slide", "inverse", "hide_logo")) {
element <- if (!is.null(link_url)) 'a' else 'div'
link <- if (!is.null(link_url)) sprintf("'%s'", link_url) else "null"
if (!is.null(exclude_class) && length(exclude_class)) {
for (i in seq_along(exclude_class)) {
if (!substr(exclude_class[i], 1, 1) == ".") {
exclude_class[i] <- paste0(".", exclude_class[i])
}
}
exclude_class <- paste(sprintf(":not(%s)", exclude_class), collapse = "")
} else {
exclude_class <- ""
}
sprintf("(function () {
let tries = 0
function addLogo () {
if (typeof slideshow === 'undefined') {
tries += 1
if (tries < 10) {
setTimeout(addLogo, 100)
}
} else {
document.querySelectorAll('.remark-slide-content%s')
.forEach(function (slide) {
const logo = document.createElement('%s')
logo.classList = 'xaringan-extra-logo'
logo.href = %s
slide.appendChild(logo)
})
}
}
document.addEventListener('DOMContentLoaded', addLogo)
})()",
exclude_class, element, link)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/use_logo.R |
# use y if x is.null
`%||%` <- function(x, y) if (is.null(x)) y else x
xe_file <- function(...) {
system.file(..., package = "xaringanExtra", mustWork = TRUE)
}
xaringan_version <- function(min = NULL) {
xv <- utils::packageVersion("xaringan")
if (is.null(min)) {
return(xv)
}
xv >= package_version(min)
}
compact <- function(.l) {
is_null <- vapply(.l, is.null, logical(1))
is_len_0 <- vapply(.l, length, integer(1)) == 0
.l[!(is_null | is_len_0)]
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/utils.R |
#' Webcam
#'
#' Add a live video of your webcam into your slides (in your own browser only).
#' Useful when you are presenting via video conference to include your video,
#' or when you are recording a class or lecture.
#'
#' @includeRmd man/fragments/webcam-details.Rmd details
#'
#' @examples
#' use_webcam()
#'
#' @references The webcam extension is based on the original
#' [webcam implementation](https://yihui.org/en/2017/12/html5-camera/) by
#' Yihui Xie, author of \pkg{xaringan}.
#' @name webcam
NULL
#' @describeIn webcam Add the webcam extension to your slides
#' @param width,height Width and height of the video pane in absolute CSS units,
#' i.e. as `200` or `"200px"`.
#' @param margin Margin around the video pane in CSS units.
#'
#' @return An `htmltools::tagList()` with the HTML dependencies required for
#' **webcam**.
#'
#' @export
use_webcam <- function(width = 200, height = 200, margin = "1em") {
htmltools::tagList(
html_dependency_webcam(width, height, margin)
)
}
#' @describeIn webcam Returns an [htmltools::htmlDependency()] with the webcam
#' dependencies. Most users will want to use `use_webcam()`.
#' @export
html_dependency_webcam <- function(width = 200, height = 200, margin = "1em") {
width <- validateAbsoluteCssUnit(width)
height <- validateAbsoluteCssUnit(height)
margin <- htmltools::validateCssUnit(margin)
opts <- sprintf('{"width":"%s","height":"%s","margin":"%s"}', width, height, margin)
opts <- sprintf(
'<script id="xaringanExtra-webcam-options" type="application/json">%s</script>',
opts
)
htmltools::htmlDependency(
name = "xaringanExtra-webcam",
version = "0.0.1",
package = "xaringanExtra",
src = "webcam",
script = "webcam.js",
head = opts,
all_files = FALSE
)
}
validateAbsoluteCssUnit <- function(x) {
var <- deparse(substitute(x))
x <- htmltools::validateCssUnit(x)
if (!grepl("px$", x)) {
stop(
var,
" must be expressed in absolute integer ",
"or pixel units.",
call. = FALSE
)
}
sub("px$", "", x)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/webcam.R |
#' xaringanExtra: Extensions for xaringan
#'
#' `xaringanExtra` is a playground of enhancements and extensions for
#' \pkg{xaringan} slides.
#'
#' - Add an overview of your presentation with [use_tile_view()]
#' - Make your slide content editable with [use_editable()]
#' - Share your slides in style with [use_share_again()]
#' - Broadcast your slides in real time to viewers with [use_broadcast()]
#' - Scribble on your slides during your presentation with [use_scribble()]
#' - Announce slide changes with a subtle tone: [use_slide_tone()]
#' - Animate slide transitions with [use_animate_css()]
#' - Add tabbed panels to slides with [use_panelset()]
#' - Add a logo to all of your slides with [use_logo()]
#' - Add a top or bottom banner to all of your slides with [use_banner()]
#' - Add a search box to search through your slides with [use_search()]
#' - Use the Tachyons CSS utility toolkit: [use_tachyons()]
#' - Add a live video feed to you slides with [use_webcam()]
#' - Always play gifs from the start with [use_freezeframe()]
#' - Add one-click code copying with [use_clipboard()]
#' - Fit your slides to fill the browser window: [use_fit_screen()]
#'
#' @keywords internal
"_PACKAGE"
#' Use xaringanExtra Extensions
#'
#' Load multiple \pkg{xaringanExtra} extensions at once. All extensions can be
#' loaded with this function.
#'
#' @examples
#' use_xaringan_extra(c("tile_view", "panelset"))
#' use_xaringan_extra(c("tile_view", "scribble", "share_again"))
#'
#' @return An `htmltools::tagList()` with the [htmltools::htmlDependency()]s
#' for the requested extensions.
#' @param include Character vector of extensions to include. One or more of
#' `"tile_view"`, `"editable"`, `"share_again"`, `"broadcast"`, `"slide_tone"`,
#' `"animate_css"`, `"panelset"` `"tachyons"`, `"fit_screen"`, `"webcam"`,
#' `"clipboard"`, `"search"`, `"scribble"`, `"freezeframe"`.
#' @export
use_xaringan_extra <- function(include = c(
"tile_view",
"animate_css",
"tachyons",
"panelset",
"broadcast",
"share_again",
"scribble"
)) {
opts <- c(
"tile_view",
"animate_css",
"tachyons",
"slide_tone",
"fit_screen",
"panelset",
"editable",
"webcam",
"clipboard",
"share_again",
"broadcast",
"search",
"scribble",
"freezeframe"
)
include <- match.arg(include, opts, TRUE)
includes <- function(x) x %in% include
htmltools::tagList(
if (includes("tile_view")) html_dependency_tile_view(),
if (includes("animate_css")) html_dependency_animate_css(),
if (includes("tachyons")) html_dependency_tachyons(),
if (includes("slide_tone")) html_dependency_slide_tone(),
if (includes("fit_screen")) html_dependency_fit_screen(),
if (includes("panelset")) use_panelset(),
if (includes("editable")) html_dependency_editable(),
if (includes("webcam")) html_dependency_webcam(),
if (includes("clipboard")) use_clipboard(),
if (includes("share_again")) use_share_again(),
if (includes("broadcast")) use_broadcast(),
if (includes("search")) use_search(),
if (includes("scribble")) use_scribble(),
if (includes("freezeframe")) use_freezeframe()
)
}
# The following block is used by usethis to automatically manage
# roxygen namespace tags. Modify with care!
## usethis namespace: start
## usethis namespace: end
NULL
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/R/xaringanExtra-package.R |
To equip your slides with broadcast capabilities,
add the following chunk to your slides' `.Rmd` file.
````markdown
```{r broadcast, echo=FALSE}`r ''`
xaringanExtra::use_broadcast()
```
````
Then, host your slides online,
either on a personal webpage,
or through
[Netlify](https://www.netlify.com/),
[GitHub Pages](https://pages.github.com/),
[GitLab Pages](https://docs.gitlab.com/ee/user/project/pages/),
or another service.
When you want to present,
open the version of your slides hosted online in a modern browser.
Then press <kbd>P</kbd> to enter the presenter view.
Click on the **Broadcast** button to start broadcasting.
`r if(exists("IN_README")) ""`
After a short moment,
if everything works,
the broadcast button will turn into a broadcast link.
Share this link with your audience.
When they open the link,
their browser will connect with yours and from then on,
whenever you advance or change slides,
your viewer's slides will move to the current slide.
Note that the broadcast link is unique
and, as the presenter,
is remembered for 4 hours.
After 4 hours of inactivity,
a new link will be generated.
In general, create and share the broadcast link
just before or as your event starts
and certainly not more than an hour before the presentation.
### How It Works
PeerJS creates a direct, peer-to-peer connection between your browser
and your viewer's browsers.
A third party PeerJS server is used to initially facilitate the connection
using the broadcast ID to connect with the presenter's browser.
After the connection is made,
data is sent directly between browsers
and the PeerJS server is no longer involved.
Furthermore, at no time is any information
about your presentation transmitted over the network.
When you move to a slide, say for example slide 11,
**broadcast** announces "Slide 11" to any connected viewers
and JavaScript in their browser moves their presentation to slide 11.
This has two consequences:
1. Viewers can move around and look at slides
other than the one currently active in the presenter's browser.
When the presenter changes slides, however,
all viewers' slides will move to the new slide.
1. If your slides involve interactivity,
such as [htmlwidgets](https://www.htmlwidgets.org/)
or [panelset],
changes made in the presenter's view
aren't replicated for viewers.
Viewers will be taken to the same slide as the presenter,
but they will need to click on their own to follow interactively.
### Extra Details
It's worth mentioning a few details.
First of all, the broadcaster needs to be connected first before viewers connect.
If a viewer connects before the broadcaster starts (or restarts),
they should reload the link to reconnect.
Similarly, if the broadcaster reloads their slides,
viewers will also need to reload to reconnect.
But once everyone is connected,
a message will appear for the viewer to prompt them to reconnect.
If you are the presenter and you load the broadcast link,
the broadcast will automatically reconnect and start broadcasting.
If you want to view your slides without broadcasting,
just load the plain URL for the slides without the `?broadcast=...` portion.
From this view,
you can restart the broadcast from the presenter view
and if the broadcast ID is still valid that ID will be used.
To reset the broadcast ID without waiting 4 hours,
load your slides with `?broadcast=1`
and new broadcast link will be created at the next broadcast.
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/man/fragments/broadcast-details.Rmd |
To add **clipboard** to your xaringan presentation or R Markdown document,
add the following code chunk to your slides' R Markdown file.
````markdown
```{r xaringanExtra-clipboard, echo=FALSE}`r ''`
xaringanExtra::use_clipboard()
```
````
You can also customize the text that is shown
by default when hovering over a code chunk
with the `button_text` argument.
Use `success_text` to specify the text shown when the copy action works,
or `error_text` for the text shown when the copy action fails.
If the copy action fails, the text will still be selected,
so the user can still manually press `Ctrl+C` to copy the code chunk.
These options accept raw HTML strings,
so you can achieve an icon-only appearance using FontAwesome icons:
````markdown
```{r xaringanExtra-clipboard, echo=FALSE}`r ''`
htmltools::tagList(
xaringanExtra::use_clipboard(
button_text = "<i class=\"fa fa-clipboard\"></i>",
success_text = "<i class=\"fa fa-check\" style=\"color: #90BE6D\"></i>",
error_text = "<i class=\"fa fa-times-circle\" style=\"color: #F94144\"></i>"
),
rmarkdown::html_dependency_font_awesome()
)
```
````
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/man/fragments/clipboard-details.Rmd |
```{r echo=FALSE, results="asis"}
if (!exists("INCLUDE_CHILD_HEADER") || isTRUE(INCLUDE_CHILD_HEADER)) {
cat("# Panelset knitr Chunks")
}
```
A common use-case for **panelset**
is to show the code and its output in separate tabs.
For example,
you might want to first show the code to create a plot in the first tab,
with the plot itself in a second tab.
On slides where space is constrained,
this approach can be useful.
To help facilitate this process,
**panelset** provides a `panelset` chunk option.
When set to `TRUE`,
the code is included in a panel tab named _Code_
and the output is included in a panel tab named _Output_.
Note that you still need to wrap this chunk in a panelset-creating container.
````markdown
.panelset[
```{r panelset = TRUE}`r ''`
list(
normal = rnorm(10),
uniform = runif(10),
cauchy = rcauchy(10)
)
```
]
````
You can also set the `panelset` chunk option to a named vector,
where the `source` item is the tab name for the source code
and the `output` item is the tab name for the code output.
````markdown
```{r panelset = c(source = "ggplot2", output = "Plot")}`r ''`
ggplot(Orange) +
aes(x = age, y = circumference, colour = Tree) +
geom_point() +
geom_line() +
guides(colour = FALSE) +
theme_bw()
```
````
When your code contains multiple expressions and outputs,
you may also want to set the `results = "hold"` chunk option.
Currently, knitr uses `results = "markup"` as the default,
in which case each code expression and output pair will generate a pair of tabs.
````markdown
```{r panelset = TRUE, results="hold"}`r ''`
print("Oak is strong and also gives shade.")
print("The lake sparkled in the red hot sun.")
```
````
Finally, panelset chunks also work in R Markdown documents,
but they must be encapsulated in `<div class="panelset">` and `</div>`
````markdown
<div class="panelset">
```{r panelset = TRUE}`r ''`
print("Oak is strong and also gives shade.")
```
</div>
````
or appear inside a section with the panelset class.
````markdown
### A Random Sentence {.panelset}
```{r panelset = TRUE}`r ''`
print("Oak is strong and also gives shade.")
```
````
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/man/fragments/panelset_chunks.Rmd |
```{r echo=FALSE, results="asis"}
if (!exists("INCLUDE_CHILD_HEADER") || isTRUE(INCLUDE_CHILD_HEADER)) {
cat("# Style Panelset")
}
```
To customize the appearance of your panels,
you can use `style_panelset_tabs()`
called directly in an R chunk in your slides.
````markdown
```{r echo=FALSE}`r ''`
style_panelset_tabs(foreground = "honeydew", background = "seagreen")
```
````
The panelset uses opacity to soften the in-active tabs
to increase the chances that the tabs will work with your slide theme.
If you decide to change your tab colors
or to use solid colored tabs,
you'll likely want to set `inactive_opacity = 1` in `style_panelset()`
(or the corresponding `--panel-tab-inactive-opacity` CSS variable).
Behind the scenes,
`style_panelset_tabs()` updates the values of
[custom CSS properties](https://developer.mozilla.org/en-US/docs/Web/CSS/--*)
that define the panelset appearance.
If you'd rather work with CSS,
the default values of these properties are shown in the CSS code below.
You can copy the whole CSS block to your slides
and modify the values to customize the style to fit your presentation.
````markdown
```{css echo=FALSE}`r ''`
.panelset {
--panel-tab-foreground: currentColor;
--panel-tab-background: unset;
--panel-tab-active-foreground: currentColor;
--panel-tab-active-background: unset;
--panel-tab-active-border-color: currentColor;
--panel-tab-hover-foreground: currentColor;
--panel-tab-hover-background: unset;
--panel-tab-hover-border-color: currentColor;
--panel-tab-inactive-opacity: 0.5;
--panel-tabs-border-bottom: #ddd;
--panel-tab-font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace;
}
```
````
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/man/fragments/panelset_custom-styles.Rmd |
```{r echo=FALSE, results="asis"}
if (!exists("INCLUDE_CHILD_HEADER") || isTRUE(INCLUDE_CHILD_HEADER)) {
cat("# Usage in R Markdown")
}
```
Panelset works in all R Markdown HTML outputs
like HTML reports and [blogdown](https://bookdown.org/yihui/blogdown/) webpages!
Panelset works in the same way as
`rmarkdown`'s [tabset](https://bookdown.org/yihui/rmarkdown-cookbook/html-tabs.html) feature,
albeit with fewer style options,
but the trade-off is that it works in a wider range of document types.
Generally, as long as the output is HTML, panelset should work.
Another advantage of panelset is that it enables deeplinking:
the currently shown tab is encoded in the URL automatically,
allowing users to link to open tabs.
Users can also right click on a panel's tab
and select _Copy Link_ to link directly to a specific panel's tab,
which will appear in view when visiting the copied link.
With standard R Markdown, i.e. [rmarkdown::html_document()],
you can use the following template.
```markdown
# Panelset In R Markdown! {.panelset}
## Tab One
Amet enim aptent molestie vulputate pharetra
vulputate primis et vivamus semper.
## Tab Two
### Sub heading one
Sit etiam malesuada arcu fusce ullamcorper
interdum proin tincidunt curabitur felis?
## Tab Three
Adipiscing mauris egestas vitae pretium
ad dignissim dictumst platea!
# Another section
This content won't appear in a panel.
```
In other,
less-standard R Markdown HTML formats,
you can use pandoc's [fenced divs](https://pandoc.org/MANUAL.html#extension-fenced_divs).
````markdown
::::: {.panelset}
::: {.panel}
[First Tab]{.panel-name}
Lorem sed non habitasse nulla donec egestas magna
enim posuere fames ante diam!
:::
::: {.panel}
[Second Tab]{.panel-name}
Consectetur ligula taciti neque scelerisque gravida
class pharetra netus lobortis quisque mollis iaculis.
:::
:::::
````
Alternatively, you can also use raw HTML.
````html
<div class="panelset">
<div class="panel">
<div class="panel-name">First Tab</div>
<!-- Panel content -->
<p>Lorem ipsum, etc, etc</p>
</div>
<div class="panel">
<div class="panel-name">Second Tab</div>
<!-- Panel content -->
<p>Lorem ipsum, etc, etc</p>
</div>
</div>
````
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/man/fragments/panelset_other-rmd.Rmd |
```{r echo=FALSE, results="asis"}
if (!exists("INCLUDE_CHILD_HEADER") || isTRUE(INCLUDE_CHILD_HEADER)) {
cat("# Sideways Panelsets")
}
```
As an alternative to the "tabs above content" view,
you can also use _sideways_ panelsets
where the tabs appear beside the tabbed content.
To choose this effect,
add the `.sideways` class to `.panelset` in your slides or R Markdown text.
````markdown
.panelset.sideways[
.panel[.panel-name[ui.R]
```r
# shiny ui code here...
```
]
.panel[.panel-name[server.R]
```r
function(input, output, session) {
# shiny server code here...
}
```
]
]
````
By default in sideways-mode, the tabs will appear on the left side.
You can choose to place the tabs on the right side
by including both `.sideways` and `.right` with `.panelset`.
````markdown
.panelset.sideways.right[
.panel[.panel-name[ui.R]
```r
# shiny ui code here...
```
]
.panel[.panel-name[server.R]
```r
function(input, output, session) {
# shiny server code here...
}
```
]
]
````
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/man/fragments/panelset_sideways.Rmd |
To add **webcam** to your xaringan presentation,
add the following code chunk to your slides' R Markdown file.
````markdown
```{r}`r ''`
xaringanExtra::use_webcam()
```
````
Inside your slides,
press **w** to turn the webcam on and off,
or press **Shift** + **W** to move the video to the next corner.
You can also drag and drop the video within the browser window.
| /scratch/gouwar.j/cran-all/cranData/xaringanExtra/man/fragments/webcam-details.Rmd |
#' @title Generate lighter or darker version of a color
#' @description Produces a linear blend of the color with white or black.
#' @param color_hex A character string representing a hex color
#' @param strength The "strength" of the blend with white or black,
#' where 0 is entirely the original color and 1 is entirely white
#' (`lighten_color()`) or black (`darken_color()`).
#' @examples
#' blue <- "#0e6ba8"
#' blue_light <- lighten_color(blue, strength = 0.33)
#' blue_dark <- darken_color(blue, strength = 0.33)
#'
#' if (requireNamespace("scales", quietly = TRUE)) {
#' scales::show_col(c(blue_light, blue, blue_dark))
#' }
#' @return A character string with the lightened or darkened color in
#' hexadecimal format.
#' @name lighten_darken_color
NULL
#' @rdname lighten_darken_color
#' @export
lighten_color <- function(color_hex, strength = 0.7) {
stopifnot(strength >= 0 && strength <= 1)
color_rgb <- col2rgb(color_hex)[, 1]
color_rgb <- (1 - strength) * color_rgb + strength * 255
rgb(color_rgb[1], color_rgb[2], color_rgb[3], maxColorValue = 255)
}
#' @rdname lighten_darken_color
#' @export
darken_color <- function(color_hex, strength = 0.8) {
stopifnot(strength >= 0 && strength <= 1)
color_rgb <- col2rgb(color_hex)[, 1]
color_rgb <- (1 - strength) * color_rgb
rgb(color_rgb[1], color_rgb[2], color_rgb[3], maxColorValue = 255)
}
#' @title Add alpha to hex color
#' @description Applies alpha (or opacity) to a color in hexadecimal form by
#' converting opacity in the `[0, 1]` range to hex in the `[0, 255]` range
#' and appending to the hex color.
#' @inheritParams lighten_darken_color
#' @param opacity Desired opacity of the output color
#' @examples
#' blue <- "#0e6ba8"
#' blue_transparent <- apply_alpha(blue)
#'
#' if (requireNamespace("scales", quietly = TRUE)) {
#' scales::show_col(c(blue, blue_transparent))
#' }
#' @return A character string with added opacity level as hexadecimal characters.
#' @export
apply_alpha <- function(color_hex, opacity = 0.5) {
paste0(color_hex, as.hexmode(round(255 * opacity, 0)))
}
adjust_value_color <- function(color_hex, strength = 0.5) {
color_hsv <- rgb2hsv(col2rgb(color_hex))[, 1]
color_hsv["v"] <- strength
hsv(color_hsv[1], color_hsv[2], color_hsv[3])
}
#' Choose dark or light color
#'
#' Takes a color input as `x` and returns either the black or white color (or
#' expression) if dark or light text should be used over the input color for
#' best contrast. Follows W3C Recommendations.
#'
#' @references <https://stackoverflow.com/a/3943023/2022615>
#' @param x The background color (hex)
#' @param black Text or foreground color, e.g. "#222" or
#' `substitute(darken_color(x, 0.8))`, if black text provides the best contrast.
#' @param white Text or foreground color or expression, e.g. "#EEE" or
#' `substitute(lighten_color(x, 0.8))`, if white text provides the best contrast.
#' @examples
#' light_green <- "#c4d6b0"
#' contrast_green <- choose_dark_or_light(light_green)
#' dark_purple <- "#381d2a"
#' contrast_purple <- choose_dark_or_light(dark_purple)
#'
#' if (requireNamespace("scales", quietly = TRUE)) {
#' scales::show_col(c(light_green, contrast_green, dark_purple, contrast_purple))
#' }
#' @return The `black` color or `white` color according to which color provides
#' the greates contrast with the input color.
#'
#' @export
choose_dark_or_light <- function(x, black = "#000000", white = "#FFFFFF") {
if (is_light_color(x)) eval(black) else eval(white)
}
is_light_color <- function(x) {
# this function returns TRUE if the given color
# is light-colored and requires dark text
color_rgb <- col2rgb(x)[, 1]
# from https://stackoverflow.com/a/3943023/2022615
color_rgb <- color_rgb / 255
color_rgb[color_rgb <= 0.03928] <- color_rgb[color_rgb <= 0.03928] / 12.92
color_rgb[color_rgb > 0.03928] <- ((color_rgb[color_rgb > 0.03928] + 0.055) / 1.055)^2.4
lum <- t(c(0.2126, 0.7152, 0.0722)) %*% color_rgb
lum[1, 1] > 0.179
}
prepare_colors <- function(colors = NULL) {
if (is.null(colors) || length(colors) < 1) return(NULL)
if (is.null(names(colors))) {
stop(
"`colors` must have names corresponding to valid CSS classes",
call. = FALSE
)
}
if (any(grepl("\\s", names(colors)))) {
stop(
"Color names in `colors` must be valid CSS classes",
" and cannot contain spaces",
call. = FALSE)
}
maybe_bad_css <- unique(grep("^[_-]|[ .>~*:|+}/]", names(colors), value = TRUE))
if (length(maybe_bad_css) > 0) {
warning(
"Color names in `colors` should be valid CSS classes: ",
paste0("'", maybe_bad_css, "'", collapse = ", "),
call. = FALSE
)
}
whisker::iteratelist(colors, "color_name")
}
full_length_hex <- function(x) {
varname <- substitute(x)
bad_hex_msg <- str_wrap(
"`", deparse(varname), "` is not a hexadecimal color: \"", x, "\". ",
"theme_xaringan() requires colors to be specified in hexadecimal format.",
" If you used valid CSS colors in your xaringan theme, please convert ",
"these colors to hex format, e.g. \"#1a2b3c\"."
)
check_color_is_hex(x, stop, bad_hex_msg)
x <- sub("^#", "", x)
if (nchar(x) == 3) {
x <- strsplit(x, character(0))[[1]]
x <- rep(x, each = 2)
x <- paste(x, collapse = "")
}
paste0("#", x)
}
check_color_is_hex <- function(
color,
throw = warning,
msg = "{color} is not a hexadecimal color"
) {
is_probably_hex <- grepl("^#", color) &&
!grepl("[^#0-9a-fA-F]", color) &&
nchar(sub("^#", "", color)) %in% c(3, 6)
if (!is_probably_hex) {
msg <- glue::glue(msg)
if (!is.null(throw)) throw(str_wrap(msg), call. = FALSE)
}
is_probably_hex
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/color.R |
read_css_vars <- function(file = NULL) {
if (is.null(file)) {
css_candidates <- find_xaringan_themer_css()
file <- choose_xaringan_themer_css(css_candidates)
}
css_get_root(file)
}
find_xaringan_themer_css <- function() {
# finds xaringan themer files within or below current working directory
# and is only ever intended to be called in that situation
css_files <- list.files(pattern = "css$", recursive = TRUE, full.names = TRUE)
css_files_head <- purrr::map(css_files, readLines, n = 5)
is_xt <- grepl(pattern = "generated by xaringanthemer", css_files_head, fixed = TRUE)
css_files[is_xt]
}
choose_xaringan_themer_css <- function(css_candidates = character(0)) {
if (!length(css_candidates)) {
stop("Unable to locate a xaringanthemer css file.", call. = FALSE)
} else if (length(css_candidates) == 1) {
file <- css_candidates
} else if (length(css_candidates) > 1) {
is_xaringan_themer_css <- grepl("xaringan-themer.css", css_candidates, fixed = TRUE)
if (any(is_xaringan_themer_css)) {
file <- css_candidates[is_xaringan_themer_css][1]
} else {
file <- css_candidates[1]
message(glue::glue("Using xaringanthemer theme in {file}"))
}
}
file
}
css_get_root <- function(file) {
x <- readLines(file, warn = FALSE)
x <- paste(x, collapse = "\n")
where <- regexpr(":root\\s*\\{[^}]+\\}", x)
if (where < 0) return(NULL)
x <- substr(x, where, where + attr(where, "match.length"))
x <- strsplit(x, "\n")[[1]]
m <- regexec("--(.+):\\s*(.+?);", x)
x <- regmatches(x, m)
x <- purrr::compact(x)
vars <- gsub("-", "_", purrr::map_chr(x, `[`, 2))
values <- purrr::map(x, `[`, 3)
names(values) <- vars
for (font_type in c("text", "header", "code")) {
font_is_google <- paste0(font_type, "_font_is_google")
values[[font_is_google]] <- if (!is.null(values[[font_is_google]])) {
values[[font_is_google]] %in% c("1", "TRUE", "true", "yes")
} else FALSE
}
values
}
css_get_padding <- function(x) {
stopifnot(length(x) == 1)
x <- trimws(x)
x <- as.list(strsplit(x, " ")[[1]])
stopifnot(length(x) %in% c(1, 2, 4))
names(x) <- c("top", "right", "bottom", "left")[seq_along(x)]
list(
top = x$top,
right = x$right %||% x$top,
bottom = x$bottom %||% x$top,
left = x$left %||% x$right %||% x$top
)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/css.R |
#' A Plot Theme for ggplot2 by xaringanthemer
#'
#' @description
#'
#' `r lifecycle::badge("maturing")`
#'
#' Creates \pkg{ggplot2} themes to match the xaringanthemer theme used in the
#' \pkg{xaringan} slides that seamlessly matches the "normal" slide colors and
#' styles. See `vignette("ggplot2-themes")` for more information and examples.
#'
#' @param text_color Color for text and foreground, inherits from `text_color`
#' @param background_color Color for background, inherits from
#' `background_color`
#' @param accent_color Color for titles and accents, inherits from
#' `header_color`
#' @param accent_secondary_color Color for secondary accents, inherits from
#' `text_bold_color`
#' @param css_file Path to a \pkg{xaringanthemer} CSS file, from which the
#' theme variables and values will be inferred. In general, if you use the
#' \pkg{xaringathemer} defaults, you will not need to set this. This feature
#' lets you create a \pkg{ggplot2} theme for your \pkg{xaringan} slides, even
#' if you have only saved your theme CSS file and you aren't creating your
#' CSS theme with \pkg{xaringanthemer} in your slides' source file.
#' @inheritParams theme_xaringan_base
#'
#' @examples
#' # Requires ggplot2
#' has_ggplot2 <- requireNamespace("ggplot2", quietly = TRUE)
#'
#' if (has_ggplot2) {
#' # Because this is an example, we'll save the CSS to a temp file
#' path_to_css_file <- tempfile(fileext = ".css")
#'
#' # Create the xaringan theme: dark blue background with teal green accents
#' style_duo(
#' primary_color = "#002b36",
#' secondary_color = "#31b09e",
#' # Using basic fonts for this example, but the plot theme will
#' # automatically use your theme font if you use Google fonts
#' text_font_family = "sans",
#' header_font_family = "serif",
#' outfile = path_to_css_file
#' )
#'
#' library(ggplot2)
#' ggplot(mpg) +
#' aes(cty, hwy) +
#' geom_point() +
#' ggtitle("Fuel Efficiency of Various Cars") +
#' theme_xaringan()
#' }
#' @return A ggplot2 theme
#' @family xaringanthemer ggplot2 themes
#' @export
theme_xaringan <- function(
text_color = NULL,
background_color = NULL,
accent_color = NULL,
accent_secondary_color = NULL,
css_file = NULL,
set_ggplot_defaults = TRUE,
text_font = NULL,
text_font_use_google = NULL,
text_font_size = NULL,
title_font = NULL,
title_font_use_google = NULL,
title_font_size = NULL,
use_showtext = NULL
) {
requires_xaringanthemer_env(css_file = css_file, try_css = TRUE)
requires_package(fn = "xaringan_theme")
background_color <- background_color %||% xaringanthemer_env$background_color
text_color <- text_color %||% xaringanthemer_env$text_color
accent_color <- accent_color %||% xaringanthemer_env$header_color
accent_secondary_color <- accent_secondary_color %||% xaringanthemer_env$text_bold_color %||% accent_color
theme_xaringan_base(
text_color,
background_color,
accent_color = accent_color,
accent_secondary_color = accent_secondary_color,
set_ggplot_defaults = set_ggplot_defaults,
text_font = text_font,
text_font_use_google = text_font_use_google,
text_font_size = text_font_size,
title_font = title_font,
title_font_use_google = title_font_use_google,
title_font_size = title_font_size,
use_showtext = use_showtext
)
}
#' An Inverse Plot Theme for ggplot2 by xaringanthemer
#'
#' @description
#'
#' `r lifecycle::badge("maturing")`
#'
#' A \pkg{ggplot2} xaringanthemer plot theme to seamlessly match the "inverse"
#' \pkg{xaringan} slide colors and styles as styled by [xaringanthemer]. See
#' `vignette("ggplot2-themes")` for more information and examples.
#'
#' @param text_color Color for text and foreground, inherits from `text_color`
#' @param background_color Color for background, inherits from
#' `background_color`
#' @param accent_color Color for titles and accents, inherits from
#' `header_color`
#' @param accent_secondary_color Color for secondary accents, inherits from
#' `text_bold_color`
#' @inheritParams theme_xaringan
#' @inheritParams theme_xaringan_base
#'
#' @examples
#' # Requires ggplot2
#' has_ggplot2 <- requireNamespace("ggplot2", quietly = TRUE)
#'
#' if (has_ggplot2) {
#' # Because this is an example, we'll save the CSS to a temp file
#' path_to_css_file <- tempfile(fileext = ".css")
#'
#' # Create the xaringan theme: dark blue background with teal green accents
#' style_duo(
#' primary_color = "#002b36",
#' secondary_color = "#31b09e",
#' # Using basic fonts for this example, but the plot theme will
#' # automatically use your theme font if you use Google fonts
#' text_font_family = "sans",
#' header_font_family = "serif",
#' outfile = path_to_css_file
#' )
#'
#' library(ggplot2)
#' ggplot(mpg) +
#' aes(cty, hwy) +
#' geom_point() +
#' ggtitle("Fuel Efficiency of Various Cars") +
#' # themed to match the inverse slides: teal background with dark blue text
#' theme_xaringan_inverse()
#' }
#' @return A ggplot2 theme
#' @family xaringanthemer ggplot2 themes
#' @export
theme_xaringan_inverse <- function(
text_color = NULL,
background_color = NULL,
accent_color = NULL,
accent_secondary_color = NULL,
css_file = NULL,
set_ggplot_defaults = TRUE,
text_font = NULL,
text_font_use_google = NULL,
text_font_size = NULL,
title_font = NULL,
title_font_use_google = NULL,
title_font_size = NULL,
use_showtext = NULL
) {
requires_xaringanthemer_env(css_file = css_file, try_css = TRUE)
requires_package(fn = "xaringan_theme")
background_color <- background_color %||% xaringanthemer_env$inverse_background_color
text_color <- text_color %||% xaringanthemer_env$inverse_text_color
accent_color <- accent_color %||% xaringanthemer_env$inverse_header_color
accent_secondary_color <- accent_secondary_color %||% accent_color
theme_xaringan_base(
text_color,
background_color,
accent_color = accent_color,
accent_secondary_color = accent_secondary_color,
set_ggplot_defaults = set_ggplot_defaults,
text_font = text_font,
text_font_use_google = text_font_use_google,
text_font_size = text_font_size,
title_font = title_font,
title_font_use_google = title_font_use_google,
title_font_size = title_font_size,
use_showtext = use_showtext
)
}
#' The ggplot2 xaringanthemer base plot theme
#'
#' @description
#'
#' `r lifecycle::badge("maturing")`
#'
#' Provides a base plot theme for \pkg{ggplot2} to match the \pkg{xaringan}
#' slide theme created by [xaringanthemer]. The theme is designed to create a
#' general plot style from two colors, a `background_color` and a `text_color`
#' (or foreground color). Also accepts an `accent_color` and an
#' `accent_secondary_color` that are [xaringanthemer] is not required for the
#' base theme. Use [theme_xaringan()] or [theme_xaringan_inverse()] in xaringan
#' slides styled by xaringanthemer for a plot theme that matches the slide
#' style. See `vignette("ggplot2-themes")` for more information and examples.
#'
#' @param text_color Color for text and foreground
#' @param background_color Color for background
#' @param accent_color Color for titles and accents, inherits from
#' `header_color` or `text_color`. Used for the `title` base setting in
#' [ggplot2::theme()], and additionally for setting the `color` or `fill` of
#' \pkg{ggplot2} geom defaults.
#' @param accent_secondary_color Color for secondary accents, inherits from
#' `text_bold_color` or `accent_color`. Used only when setting \pkg{ggplot2} geom
#' defaults.
#' @param set_ggplot_defaults Should defaults be set for \pkg{ggplot2} _geoms_?
#' Defaults to TRUE. To restore ggplot's defaults, or the previously set geom
#' defaults, see [theme_xaringan_restore_defaults()].
#' @param text_font Font to use for text elements, passed to
#' [sysfonts::font_add_google()], if available and `text_font_use_google` is
#' `TRUE`. Inherits from `text_font_family`. If manually specified, can be a
#' [google_font()].
#' @param text_font_use_google Is `text_font` available on [Google
#' Fonts](https://fonts.google.com)?
#' @param text_font_size Base text font size, inherits from `text_font_size`, or
#' defaults to 11.
#' @param title_font Font to use for title elements, passed to
#' [sysfonts::font_add_google()], if available and `title_font_use_google` is
#' `TRUE`. Inherits from `title_font_family`. If manually specified, can be a
#' [google_font()].
#' @param title_font_use_google Is `title_font` available on [Google
#' Fonts](https://fonts.google.com)?
#' @param title_font_size Base text font size, inherits from `title_font_size`,
#' or defaults to 14.
#' @param use_showtext If `TRUE` the \pkg{showtext} package will be
#' used to register Google fonts. Set to `FALSE` to disable this feature
#' entirely, which may result in errors during plotting if the fonts used are
#' not available locally. The default is `TRUE` when the \pkg{showtext}
#' package is installed.
#' @param ... Ignored
#'
#' @examples
#' # Requires ggplot2
#' has_ggplot2 <- requireNamespace("ggplot2", quietly = TRUE)
#'
#' if (has_ggplot2) {
#' library(ggplot2)
#'
#' plot1 <- ggplot(mpg) +
#' aes(cty, hwy) +
#' geom_point() +
#' theme_xaringan_base(
#' text_color = "#602f6b", # imperial
#' background_color = "#f8f8f8", # light gray
#' accent_color = "#317873", # myrtle green
#' title_font = "sans",
#' text_font = "serif",
#' set_ggplot_defaults = TRUE
#' ) +
#' labs(
#' title = "Fuel Efficiency of Various Cars",
#' subtitle = "+ theme_xaringan_base()",
#' caption = "xaringanthemer"
#' )
#'
#' print(plot1)
#'
#' plot2 <- ggplot(mpg) +
#' aes(hwy) +
#' geom_histogram(binwidth = 2) +
#' theme_xaringan_base(
#' text_color = "#a8a9c8", # light purple
#' background_color = "#303163", # deep slate purple
#' accent_color = "#ffff99", # canary yellow
#' title_font = "sans",
#' text_font = "serif",
#' set_ggplot_defaults = TRUE
#' ) +
#' labs(
#' title = "Highway Fuel Efficiency",
#' subtitle = "+ theme_xaringan_base()",
#' caption = "xaringanthemer"
#' )
#'
#' print(plot2)
#' }
#' @return A ggplot2 theme
#' @family xaringanthemer ggplot2 themes
#' @export
theme_xaringan_base <- function(
text_color,
background_color,
...,
set_ggplot_defaults = TRUE,
accent_color = NULL,
accent_secondary_color = NULL,
text_font = NULL,
text_font_use_google = NULL,
text_font_size = NULL,
title_font = NULL,
title_font_use_google = NULL,
title_font_size = NULL,
use_showtext = NULL
) {
text_color <- full_length_hex(text_color)
background_color <- full_length_hex(background_color)
blend <- color_blender(text_color, background_color)
text_font_size <- text_font_size %||% web_to_point(xaringanthemer_env$text_font_size, scale = 1.25) %||% 11
title_font_size <- title_font_size %||% web_to_point(xaringanthemer_env$header_h3_font_size, scale = 0.8) %||% 14
text_font_use_google <- text_font_use_google %||% is_google_font(text_font)
title_font_use_google <- title_font_use_google %||% is_google_font(title_font)
if (is.null(use_showtext)) {
use_showtext <- requires_package("showtext", "theme_xaringan", required = FALSE)
}
text_font <- if (!is.null(text_font)) {
register_font(text_font, identical(text_font_use_google, TRUE) && use_showtext)
} else {
get_theme_font("text")
}
title_font <- if (!is.null(title_font)) {
register_font(title_font, identical(title_font_use_google, TRUE) && use_showtext)
} else {
get_theme_font("header")
}
text_font <- text_font %||% "sans"
title_font <- title_font %||% "sans"
if (set_ggplot_defaults) {
accent_color <- accent_color %||% xaringanthemer_env$header_color %||% text_color
accent_secondary_color <- accent_secondary_color %||% xaringanthemer_env$text_bold_color %||% accent_color
accent_color <- full_length_hex(accent_color)
accent_secondary_color <- full_length_hex(accent_secondary_color)
theme_xaringan_set_defaults(
text_color = text_color,
background_color = background_color,
accent_color = accent_color,
accent_secondary_color = accent_secondary_color,
text_font = text_font
)
}
theme <- ggplot2::theme(
line = ggplot2::element_line(color = blend(0.2)),
rect = ggplot2::element_rect(fill = background_color),
text = ggplot2::element_text(
color = blend(0.1),
family = text_font,
size = text_font_size
),
title = ggplot2::element_text(
color = accent_color,
family = title_font,
size = title_font_size
),
plot.background = ggplot2::element_rect(
fill = background_color,
color = background_color
),
panel.background = ggplot2::element_rect(
fill = background_color,
color = background_color
),
panel.grid.major = ggplot2::element_line(
color = blend(0.8),
inherit.blank = TRUE
),
panel.grid.minor = ggplot2::element_line(
color = blend(0.9),
inherit.blank = TRUE
),
axis.title = ggplot2::element_text(size = title_font_size * 0.8),
axis.ticks = ggplot2::element_line(color = blend(0.8)),
axis.text = ggplot2::element_text(color = blend(0.4)),
legend.key = ggplot2::element_rect(fill = "transparent", colour = NA),
plot.caption = ggplot2::element_text(
size = text_font_size * 0.8,
color = blend(0.3)
)
)
if (utils::packageVersion("ggplot2") >= package_version("3.3.0")) {
theme + ggplot2::theme(plot.title.position = "plot")
} else theme
}
#' Set and Restore ggplot2 geom Defaults
#'
#' @description
#'
#' `r lifecycle::badge("maturing")`
#'
#' Set \pkg{ggplot2} _geom_ defaults to match [theme_xaringan()] with
#' `theme_xaringan_set_defaults()` and restore the standard or previously-set
#' defaults with `theme_xaringan_restore_defaults()`. By default,
#' `theme_xaringan_set_defaults()` is run with [theme_xaringan()] or
#' [theme_xaringan_inverse()].
#'
#' @family xaringanthemer ggplot2 themes
#' @param text_font Font to use for text elements, passed to
#' [sysfonts::font_add_google()], if available and `text_font_use_google` is
#' `TRUE`. Inherits from `text_font_family`. Must be a length-one character.
#' @inheritParams theme_xaringan
#' @inheritParams theme_xaringan_base
#' @return Invisibly returns a list of the current ggplot2 geom defaults
#' @export
theme_xaringan_set_defaults <- function(
text_color = NULL,
background_color = NULL,
accent_color = text_color,
accent_secondary_color = accent_color,
text_font = NULL
) {
requires_package("ggplot2")
blend <- color_blender(text_color, background_color)
xaringan_theme_defaults <- list(
"line" = list(color = text_color),
"vline" = list(color = accent_secondary_color),
"hline" = list(color = accent_secondary_color),
"abline" = list(color = accent_secondary_color),
"segment" = list(color = text_color),
"bar" = list(fill = accent_color),
"col" = list(fill = accent_color),
"boxplot" = list(color = text_color),
"contour" = list(color = text_color),
"density" = list(color = text_color,
fill = text_color,
alpha = 0.1),
"dotplot" = list(color = accent_color),
"errorbarh" = list(color = text_color),
"crossbar" = list(color = text_color),
"errorbar" = list(color = text_color),
"linerange" = list(color = text_color),
"pointrange" = list(color = text_color),
"map" = list(color = text_color),
"path" = list(color = text_color),
"line" = list(color = text_color),
"step" = list(color = text_color),
"point" = list(color = accent_color),
"polygon" = list(color = accent_color,
fill = accent_color),
"quantile" = list(color = text_color),
"rug" = list(color = blend(0.5)),
"segment" = list(color = text_color),
"smooth" = list(fill = blend(0.75),
color = accent_secondary_color),
"spoke" = list(color = text_color),
"label" = list(color = text_color,
family= text_font %||% get_theme_font("text")),
"text" = list(color = text_color,
family= text_font %||% get_theme_font("text")),
"rect" = list(fill = text_color),
"tile" = list(fill = text_color),
"violin" = list(fill = text_color),
"sf" = list(color = text_color)
)
geom_names <- purrr::set_names(names(xaringan_theme_defaults))
previous_defaults <- lapply(
geom_names,
function(geom) safely_set_geom(geom, xaringan_theme_defaults[[geom]])
)
if (is.null(xaringanthemer_env$old_ggplot_defaults)) {
xaringanthemer_env$old_ggplot_defaults <- previous_defaults
}
invisible(previous_defaults)
}
#' @describeIn theme_xaringan_set_defaults Restore previous or standard
#' \pkg{ggplot2} _geom_ defaults.
#' @return Invisibly returns a list of the current ggplot2 geom defaults
#' @export
theme_xaringan_restore_defaults <- function() {
requires_package("ggplot2")
requires_xaringanthemer_env(try_css = FALSE, requires_theme = FALSE)
if (is.null(xaringanthemer_env$old_ggplot_defaults)) {
return(invisible())
}
old_default <- xaringanthemer_env$old_ggplot_defaults
old_default_not_std <- vapply(old_default, function(x) length(x) > 0, logical(1))
old_default <- old_default[old_default_not_std]
restore_default <- utils::modifyList(xaringanthemer_env$std_ggplot_defaults, old_default)
geom_names <- purrr::set_names(names(restore_default))
previous_defaults <- lapply(
geom_names,
function(geom) safely_set_geom(geom, restore_default[[geom]])
)
invisible(previous_defaults)
}
safely_set_geom <- function(geom, new) {
warn <- function(x) {
warning(x$message, call. = TRUE, immediate. = TRUE)
invisible()
}
tryCatch(
{
ggplot2::update_geom_defaults(geom, new)
},
error = warn,
warning = warn
)
}
# Color Scales ------------------------------------------------------------
#' Themed ggplot2 Scales
#'
#' @description
#'
#' `r lifecycle::badge("maturing")`
#'
#' Color and fill single-color scales for discrete and continuous values,
#' created using the primary accent color of the xaringanthemer styles. See
#' `vignette("ggplot2-themes")` for more information and examples of
#' \pkg{xaringanthemer}'s \pkg{ggplot2}-related functions.
#'
#' @param ... Arguments passed on to either the \pkg{colorspace} scale
#' functions — one of [colorspace::scale_color_discrete_sequential()],
#' [colorspace::scale_color_continuous_sequential()],
#' [colorspace::scale_fill_discrete_sequential()], or
#' [colorspace::scale_fill_continuous_sequential()] — or to
#' [ggplot2::continuous_scale] or [ggplot2::discrete_scale].
#' @param color A color value, in hex, to override the default color. Otherwise,
#' the primary color of the resulting scale is chosen from the xaringanthemer
#' slide styles.
#' @param inverse If `color` is not supplied and `inverse = TRUE`, a primary
#' color is chosen to work well with the inverse slide styles, namely the
#' value of `inverse_header_color`
#' @param direction Direction of the discrete scale. Use values less than 0 to
#' reverse the direction, e.g. `direction = -1`.
#' @inheritParams colorspace::scale_color_continuous_sequential
#' @param aes_type The type of aesthetic to which the scale is being applied.
#' One of "color", "colour", or "fill".
#'
#'
#' @examples
#' # Requires ggplot2
#' has_ggplot2 <- requireNamespace("ggplot2", quietly = TRUE)
#'
#' if (has_ggplot2) {
#' library(ggplot2)
#' # Saving the theme to a temp file because this is an example
#' path_to_css_file <- tempfile(fileext = ".css")
#'
#' # Create the xaringan theme: dark blue background with teal green accents
#' style_duo(
#' primary_color = "#002b36",
#' secondary_color = "#31b09e",
#' # Using basic fonts for this example, but the plot theme will
#' # automatically use your theme font if you use Google fonts
#' text_font_family = "sans",
#' header_font_family = "serif",
#' outfile = path_to_css_file
#' )
#'
#' # Here's some very basic example data
#' ex <- data.frame(
#' name = c("Couple", "Few", "Lots", "Many"),
#' n = c(2, 3, 5, 7)
#' )
#'
#' # Fill color scales demo
#' ggplot(ex) +
#' aes(name, n, fill = n) +
#' geom_col() +
#' ggtitle("Matching fill scales") +
#' # themed to match the slides: dark blue background with teal text
#' theme_xaringan() +
#' # Fill color matches teal text
#' scale_xaringan_fill_continuous()
#'
#' # Color scales demo
#' ggplot(ex) +
#' aes(name, y = 1, color = name) +
#' geom_point(size = 10) +
#' ggtitle("Matching color scales") +
#' # themed to match the slides: dark blue background with teal text
#' theme_xaringan() +
#' # Fill color matches teal text
#' scale_xaringan_color_discrete(direction = -1)
#' }
#' @name scale_xaringan
NULL
#' @rdname scale_xaringan
#' @export
scale_xaringan_discrete <- function(
aes_type = c("color", "colour", "fill"),
...,
color = NULL,
direction = 1,
inverse = FALSE
) {
requires_package("ggplot2", "scale_xaringan_discrete")
aes_type <- match.arg(aes_type)
color <- hex2HCL(get_theme_accent_color(color, inverse))
pal <- function(n) {
colors <- colorspace::sequential_hcl(
n = n,
c1 = color[1, "C"],
l1 = color[1, "L"],
h1 = color[1, "H"],
rev = direction >= 1
)
}
ggplot2::discrete_scale(aes_type, "manual", pal, ...)
}
#' @rdname scale_xaringan
#' @export
scale_xaringan_fill_discrete <- function(
...,
color = NULL,
direction = 1,
inverse = FALSE
) {
scale_xaringan_discrete(
"fill",
...,
color = color,
direction = direction,
inverse = inverse
)
}
#' @rdname scale_xaringan
#' @export
scale_xaringan_color_discrete <- function(
...,
color = NULL,
direction = 1,
inverse = FALSE
) {
scale_xaringan_discrete(
"color",
...,
color = color,
direction = direction,
inverse = inverse
)
}
#' @rdname scale_xaringan
#' @export
scale_xaringan_colour_discrete <- scale_xaringan_color_discrete
#' @rdname scale_xaringan
#' @export
scale_xaringan_continuous <- function(
aes_type = c("color", "colour", "fill"),
...,
color = NULL,
begin = 0,
end = 1,
inverse = FALSE
) {
requires_package("ggplot2", "scale_xaringan_continuous")
requires_package("scales", "scale_xaringan_continuous")
aes_type <- match.arg(aes_type)
color <- hex2HCL(get_theme_accent_color(color, inverse))
colors <- suppressWarnings(colorspace::sequential_hcl(
n = 12,
c1 = color[1, "C"],
l1 = color[1, "L"],
h1 = color[1, "H"],
rev = TRUE
))
rescaler <- function(x, ...) {
scales::rescale(x, to = c(begin, end), from = range(x, na.rm = TRUE))
}
ggplot2::continuous_scale(
aes_type,
"continuous_sequential",
palette = scales::gradient_n_pal(colors, values = NULL),
rescaler = rescaler,
oob = scales::censor,
...
)
}
#' @rdname scale_xaringan
#' @export
scale_xaringan_fill_continuous <- function(
...,
color = NULL,
begin = 0,
end = 1,
inverse = FALSE
) {
scale_xaringan_continuous(
"fill",
...,
color = color,
begin = begin,
end = end,
inverse = inverse
)
}
#' @rdname scale_xaringan
#' @export
scale_xaringan_color_continuous <- function(
...,
color = NULL,
begin = 0,
end = 1,
inverse = FALSE
) {
scale_xaringan_continuous(
"color",
...,
color = color,
begin = begin,
end = end,
inverse = inverse
)
}
#' @rdname scale_xaringan
#' @export
scale_xaringan_colour_continuous <- scale_xaringan_color_continuous
get_theme_accent_color <- function(color = NULL, inverse = FALSE) {
color <-
if (!inverse) {
color %||%
xaringanthemer_env[["header_color"]] %||%
xaringanthemer_env[["text_color"]]
} else {
color %||% xaringanthemer_env[["inverse_header_color"]]
}
if (is.null(color)) {
stop(
call. = FALSE,
"No color provided and no default available. ",
"Have you forgotten to use a style function to set the xaringan theme?"
)
}
color
}
blend_colors <- function(x, y, alpha = 0.5) {
x <- colorspace::hex2RGB(x)
y <- colorspace::hex2RGB(y)
z <- colorspace::mixcolor(alpha, x, y)
colorspace::hex(z)
}
color_blender <- function(x, y) function(alpha = 0.5) blend_colors(x, y, alpha)
hex2HCL <- function(x) {
colorspace::coords(methods::as(colorspace::hex2RGB(x), "polarLUV"))
}
# Fonts -------------------------------------------------------------------
get_theme_font <- function(element = c("text", "header", "code"), use_showtext = TRUE) {
element <- match.arg(element)
element_family <- paste0(element, "_font_family")
element_google <- paste0(element, "_font_google")
element_is_google <- paste0(element, "_font_is_google")
element_url <- paste0(element, "_font_url")
family <- xaringanthemer_env[[element_family]]
is_google_font <- xaringanthemer_env[[element_is_google]]
if (is.null(is_google_font)) {
is_google_font <- !is.null(xaringanthemer_env[[element_google]]) ||
grepl("fonts.google", xaringanthemer_env[[element_url]], fixed = TRUE)
}
register_font(
family,
google = is_google_font,
fn = sys.calls()[[max(1, sys.nframe() - 1)]][[1]],
use_showtext = use_showtext
)
}
register_font <- function(
family,
google = TRUE,
fn = sys.calls()[[max(1, sys.nframe() - 1)]][[1]],
...,
use_showtext = TRUE
) {
if (is.null(family) || !use_showtext) {
return(NULL)
}
if (is_google_font(family)) family <- family$family
family <- gsub("['\"]", "", family)
if (!identical(xaringanthemer_env$showtext_auto, TRUE)) {
if (!requires_package(pkg = "showtext", fn, required = FALSE)) {
return(family)
}
showtext::showtext_auto()
xaringanthemer_env$showtext_auto <- TRUE
}
if (family %in% xaringanthemer_env[["registered_font_families"]] %||% "") {
return(family)
}
if (!requires_package(pkg = "sysfonts", fn, required = FALSE)) {
return(family)
} else if (family == "Droid Serif") {
dstmp <- download_tmp_droid_serif()
if (!is.null(dstmp)) {
sysfonts::font_add(
family = "Droid Serif",
regular = dstmp
)
}
} else if (!family %in% sysfonts::font_families()) {
is_default_font <- family %in% c(
"Roboto",
"Source Code Pro",
"Yanone Kaffeesatz"
)
font_found <- family %in% sysfonts::font_families()
is_google_font <- identical(google, TRUE) || (missing(google) && is_default_font)
if (is_google_font) {
tryCatch(
{
sysfonts::font_add_google(family, ...)
font_found <- TRUE
},
error = function(e) {},
warning = function(w) {}
)
}
if (!font_found) { # warn user if font still not found
msg <- if (is_google_font) glue::glue(
"Font '{family}' not found in Google Fonts. ",
"Please manually register the font using `sysfonts::font_add()`."
) else {
glue::glue(
"Font '{family}' must be manually registered using `sysfonts::font_add()`."
)
}
warning(str_wrap(msg), call. = FALSE)
} else {
verify_fig_showtext(fn)
}
}
xaringanthemer_env[["registered_font_families"]] <- c(
xaringanthemer_env[["registered_font_families"]],
family
)
family
}
download_tmp_droid_serif <- function() {
if (isTRUE(xaringanthemer_env[["declined_droid_serif"]])) return(NULL)
message(
"Using 'Droid Serif' in `theme_xaringan()` requires downloading the font from Google Fonts into a temporary file. "
)
ok_to_download <- utils::askYesNo("Do you want to try to download this font now?")
if (identical(ok_to_download, FALSE)) {
xaringanthemer_env[["declined_droid_serif"]] <- TRUE
}
if (!isTRUE(ok_to_download)) {
return(NULL)
}
dstmp <- tempfile("droid-serif", fileext = "ttf")
utils::download.file(
"https://github.com/google/fonts/raw/feb15862e0c66ec0e7531ca4c3ef2607071ea700/apache/droidserif/DroidSerif-Regular.ttf",
dstmp,
quiet = TRUE
)
dstmp
}
verify_fig_showtext <- function(fn = "theme_xaringan_base") {
if (is.null(knitr::current_input())) return()
# Try to set fig.showtext automatically
if (isTRUE(knitr::opts_current$get("fig.showtext"))) {
return()
}
stop(str_wrap(
"To use ", fn, "() with knitr, you need to set the chunk option ",
"`fig.showtext = TRUE` for this chunk. Or you can set this option ",
"globally with `knitr::opts_chunk$set(fig.showtext = TRUE)`."
))
}
set_fig_showtext <- function() {
if (!requireNamespace("showtext", quietly = TRUE)) {
return(invisible())
}
curr_fst_chunk <- knitr::opts_current$get("fig.showtext")
curr_fst <- curr_fst_chunk %||% knitr::opts_chunk$get("fig.showtext")
if (!is.null(curr_fst) && identical(curr_fst, FALSE)) {
return(invisible())
}
knitr::opts_chunk$set(fig.showtext = TRUE)
}
requires_xaringanthemer_env <- function(
css_file = NULL,
try_css = TRUE,
requires_theme = TRUE
) {
reload <- !is.null(css_file) && isTRUE(try_css)
pkg_env_exists <- exists("xaringanthemer_env")
missing_theme <- requires_theme && pkg_env_exists && is.null(xaringanthemer_env$header_color)
if (reload || !pkg_env_exists || missing_theme) {
if (try_css) {
css_vars <- read_css_vars(css_file)
for (css_var in names(css_vars)) {
xaringanthemer_env[[css_var]] <- css_vars[[css_var]]
}
return(requires_xaringanthemer_env(try_css = FALSE))
} else {
stop("Please call a xaringanthemer theme function first.")
}
}
}
#' Get the Value of xaringanthemer Style Setting
#'
#' A helper function to retrieve the value of style settings as set by a
#' xaringanthemer style function, for use in plotting and other circumstances.
#'
#' @section Style Settings:
#' Style settings used by xaringanthemer include:
#'
#' - `background_color`
#' - `background_image`
#' - `background_position`
#' - `background_size`
#' - `blockquote_left_border_color`
#' - `code_font_family`
#' - `code_font_family_fallback`
#' - `code_font_google`
#' - `code_font_is_google`
#' - `code_font_size`
#' - `code_font_url`
#' - `code_highlight_color`
#' - `code_inline_background_color`
#' - `code_inline_color`
#' - `code_inline_font_size`
#' - `extra_css`
#' - `extra_fonts`
#' - `footnote_color`
#' - `footnote_font_size`
#' - `footnote_position_bottom`
#' - `header_background_auto`
#' - `header_background_color`
#' - `header_background_content_padding_top`
#' - `header_background_ignore_classes`
#' - `header_background_padding`
#' - `header_background_text_color`
#' - `header_color`
#' - `header_font_family`
#' - `header_font_google`
#' - `header_font_is_google`
#' - `header_font_url`
#' - `header_font_weight`
#' - `header_h1_font_size`
#' - `header_h2_font_size`
#' - `header_h3_font_size`
#' - `inverse_background_color`
#' - `inverse_header_color`
#' - `inverse_text_color`
#' - `inverse_text_shadow`
#' - `left_column_selected_color`
#' - `left_column_subtle_color`
#' - `link_color`
#' - `padding`
#' - `table_border_color`
#' - `table_row_border_color`
#' - `table_row_even_background_color`
#' - `text_bold_color`
#' - `text_color`
#' - `text_font_base`
#' - `text_font_family`
#' - `text_font_family_fallback`
#' - `text_font_google`
#' - `text_font_is_google`
#' - `text_font_size`
#' - `text_font_url`
#' - `text_font_weight`
#' - `text_slide_number_color`
#' - `text_slide_number_font_size`
#' - `title_slide_background_color`
#' - `title_slide_background_image`
#' - `title_slide_background_position`
#' - `title_slide_background_size`
#' - `title_slide_text_color`
#'
#' @param setting A xaringanthemer style setting
#' @inheritParams theme_xaringan
#' @examples
#' # Create a xaringanthemer style in a temporary file for this example
#' xaringan_themer_css <- tempfile("xaringan-themer", fileext = ".css")
#'
#' style_solarized_light(outfile = xaringan_themer_css)
#'
#' theme_xaringan_get_value("text_color")
#' theme_xaringan_get_value("background_color")
#' theme_xaringan_get_value("header_color")
#' theme_xaringan_get_value("text_bold_color")
#' @return The value of the xaringanthemer style parameter.
#' @export
theme_xaringan_get_value <- function(setting, css_file = NULL) {
requires_xaringanthemer_env(css_file = css_file)
if (length(setting) > 1) {
ret <- list()
for (var in setting) {
ret[[var]] <- xaringanthemer_env[[var]]
}
return(ret)
}
xaringanthemer_env[[setting]]
}
web_to_point <- function(x, px_per_em = NULL, scale = 0.75) {
if (is.null(x)) {
return(NULL)
}
px_per_em <- px_per_em %||% get_base_font_size()
if (grepl("pt$", x)) {
return(as.numeric(sub("pt$", "", x)))
} else if (grepl("px$", x)) {
x <- as.numeric(sub("px$", "", x))
return(x * scale)
} else if (grepl("r?em$", x)) {
x <- as.numeric(sub("r?em$", "", x))
return(x * px_per_em * scale)
} else {
return()
}
}
get_base_font_size <- function() {
base_size <- xaringanthemer_env[["base_font_size"]] %||%
xaringanthemer_env[["text_font_size"]]
if (!grepl("px", base_size)) {
# assume 16px base font size
16
} else {
as.numeric(sub("px", "", base_size))
}
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/ggplot2.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param primary_color Duotone Primary Color. Defaults to #1F4257. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--primary)` in any argument of a
#' style function or in custom CSS.
#' @param secondary_color Duotone Secondary Color. Defaults to #F97B64. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--secondary)` in any argument of
#' a style function or in custom CSS.
#' @param text_color Text Color. Defaults to
#' `choose_dark_or_light(primary_color, darken_color(primary_color, 0.9), lighten_color(secondary_color, 0.99))`.
#' Modifies the `body` element. The value of this variable is also stored as
#' a CSS variable that can be referenced with `var(--text_color)` in any
#' argument of a style function or in custom CSS.
#' @param header_color Header Color. Defaults to `secondary_color`. Modifies
#' the `h1, h2, h3` elements. The value of this variable is also stored as a
#' CSS variable that can be referenced with `var(--header-color)` in any
#' argument of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to `primary_color`.
#' Modifies the `.remark-slide-content` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to `secondary_color`. Modifies the
#' `a, a > code` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--link-color)` in any argument
#' of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to `secondary_color`.
#' Modifies the `strong` element. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--text-bold-color)` in
#' any argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to `text_color`.
#' Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to
#' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
#' The value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--code-highlight-color)` in any argument of a style
#' function or in custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to `secondary_color`.
#' Modifies the `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' `secondary_color`. Modifies the `.inverse` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to `primary_color`.
#' Modifies the `.inverse` class. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--inverse-text-color)`
#' in any argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to
#' `inverse_text_color`. Modifies the `.inverse h1, .inverse h2, .inverse h3`
#' classes. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--inverse-header-color)` in any argument of a
#' style function or in custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `secondary_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-text-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `primary_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-background-color)` in any argument of a style function
#' or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' `apply_alpha(secondary_color, 0.6)`. Modifies the
#' `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' `secondary_color`. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to `apply_alpha(secondary_color, 0.5)`. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #666.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #ddd. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to `lighten_color(primary_color, 0.9)`. Modifies the
#' `thead, tfoot, tr:nth-child(even)` elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_duo
#' @family Duotone themes
#' @export
style_duo <- function(
primary_color = "#1F4257",
secondary_color = "#F97B64",
text_color = choose_dark_or_light(primary_color, darken_color(primary_color, 0.9), lighten_color(secondary_color, 0.99)),
header_color = secondary_color,
background_color = primary_color,
link_color = secondary_color,
text_bold_color = secondary_color,
text_slide_number_color = text_color,
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "rgba(255,255,0,0.5)",
code_inline_color = secondary_color,
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = secondary_color,
inverse_text_color = primary_color,
inverse_text_shadow = FALSE,
inverse_header_color = inverse_text_color,
inverse_link_color = link_color,
title_slide_text_color = secondary_color,
title_slide_background_color = primary_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = apply_alpha(secondary_color, 0.6),
left_column_selected_color = secondary_color,
blockquote_left_border_color = apply_alpha(secondary_color, 0.5),
table_border_color = "#666",
table_row_border_color = "#ddd",
table_row_even_background_color = lighten_color(primary_color, 0.9),
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
primary_color <- unname(primary_color)
secondary_color <- unname(secondary_color)
colors <- c(primary = primary_color, secondary = secondary_color, colors)
eval(parse(text = call_style_xaringan()))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_duo.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param primary_color Duotone Primary Color. Defaults to #035AA6. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--primary)` in any argument of a
#' style function or in custom CSS.
#' @param secondary_color Duotone Secondary Color. Defaults to #03A696. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--secondary)` in any argument of
#' a style function or in custom CSS.
#' @param white_color Brightest color used. Defaults to #FFFFFF. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--white)` in any argument of a
#' style function or in custom CSS.
#' @param black_color Darkest color used. Defaults to #000000. Used in multiple
#' CSS rules. The value of this variable is also stored as a CSS variable
#' that can be referenced with `var(--black)` in any argument of a style
#' function or in custom CSS.
#' @param text_color Text Color. Defaults to `black_color`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text_color)` in any argument of a style
#' function or in custom CSS.
#' @param header_color Header Color. Defaults to `primary_color`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-color)` in any argument
#' of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to `white_color`.
#' Modifies the `.remark-slide-content` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to
#' `choose_dark_or_light(secondary_color, primary_color, secondary_color)`.
#' Modifies the `a, a > code` elements. The value of this variable is also
#' stored as a CSS variable that can be referenced with `var(--link-color)`
#' in any argument of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to
#' `choose_dark_or_light(secondary_color, primary_color, secondary_color)`.
#' Modifies the `strong` element. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--text-bold-color)` in
#' any argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to
#' `primary_color`. Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to
#' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
#' The value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--code-highlight-color)` in any argument of a style
#' function or in custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to
#' `choose_dark_or_light(secondary_color, primary_color, secondary_color)`.
#' Modifies the `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' `secondary_color`. Modifies the `.inverse` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to
#' `choose_dark_or_light(secondary_color, black_color, white_color)`.
#' Modifies the `.inverse` class. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--inverse-text-color)`
#' in any argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to
#' `inverse_text_color`. Modifies the `.inverse h1, .inverse h2, .inverse h3`
#' classes. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--inverse-header-color)` in any argument of a
#' style function or in custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `choose_dark_or_light(primary_color, black_color, white_color)`. Modifies
#' the `.title-slide` class. The value of this variable is also stored as a
#' CSS variable that can be referenced with `var(--title-slide-text-color)`
#' in any argument of a style function or in custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `primary_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-background-color)` in any argument of a style function
#' or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' `apply_alpha(primary_color, 0.6)`. Modifies the
#' `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' `primary_color`. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to `apply_alpha(secondary_color, 0.5)`. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #666.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #ddd. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to `lighten_color(secondary_color, 0.8)`. Modifies the
#' `thead, tfoot, tr:nth-child(even)` elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_duo_accent
#' @family Duotone themes
#' @export
style_duo_accent <- function(
primary_color = "#035AA6",
secondary_color = "#03A696",
white_color = "#FFFFFF",
black_color = "#000000",
text_color = black_color,
header_color = primary_color,
background_color = white_color,
link_color = choose_dark_or_light(secondary_color, primary_color, secondary_color),
text_bold_color = choose_dark_or_light(secondary_color, primary_color, secondary_color),
text_slide_number_color = primary_color,
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "rgba(255,255,0,0.5)",
code_inline_color = choose_dark_or_light(secondary_color, primary_color, secondary_color),
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = secondary_color,
inverse_text_color = choose_dark_or_light(secondary_color, black_color, white_color),
inverse_text_shadow = FALSE,
inverse_header_color = inverse_text_color,
inverse_link_color = link_color,
title_slide_text_color = choose_dark_or_light(primary_color, black_color, white_color),
title_slide_background_color = primary_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = apply_alpha(primary_color, 0.6),
left_column_selected_color = primary_color,
blockquote_left_border_color = apply_alpha(secondary_color, 0.5),
table_border_color = "#666",
table_row_border_color = "#ddd",
table_row_even_background_color = lighten_color(secondary_color, 0.8),
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
primary_color <- unname(primary_color)
secondary_color <- unname(secondary_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(primary = primary_color, secondary = secondary_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan()))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_duo_accent.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param primary_color Duotone Primary Color. Defaults to #035AA6. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--primary)` in any argument of a
#' style function or in custom CSS.
#' @param secondary_color Duotone Secondary Color. Defaults to #03A696. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--secondary)` in any argument of
#' a style function or in custom CSS.
#' @param white_color Brightest color used. Defaults to #FFFFFF. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--white)` in any argument of a
#' style function or in custom CSS.
#' @param black_color Darkest color used. Defaults to #000000. Used in multiple
#' CSS rules. The value of this variable is also stored as a CSS variable
#' that can be referenced with `var(--black)` in any argument of a style
#' function or in custom CSS.
#' @param text_color Text Color. Defaults to `white_color`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text_color)` in any argument of a style
#' function or in custom CSS.
#' @param header_color Header Color. Defaults to `primary_color`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-color)` in any argument
#' of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to `black_color`.
#' Modifies the `.remark-slide-content` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to
#' `choose_dark_or_light(secondary_color, secondary_color, primary_color)`.
#' Modifies the `a, a > code` elements. The value of this variable is also
#' stored as a CSS variable that can be referenced with `var(--link-color)`
#' in any argument of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to
#' `choose_dark_or_light(secondary_color, secondary_color, primary_color)`.
#' Modifies the `strong` element. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--text-bold-color)` in
#' any argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to
#' `primary_color`. Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to
#' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
#' The value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--code-highlight-color)` in any argument of a style
#' function or in custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to
#' `choose_dark_or_light(secondary_color, secondary_color, primary_color)`.
#' Modifies the `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' `secondary_color`. Modifies the `.inverse` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to
#' `choose_dark_or_light(secondary_color, black_color, white_color)`.
#' Modifies the `.inverse` class. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--inverse-text-color)`
#' in any argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to
#' `inverse_text_color`. Modifies the `.inverse h1, .inverse h2, .inverse h3`
#' classes. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--inverse-header-color)` in any argument of a
#' style function or in custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `choose_dark_or_light(primary_color, black_color, white_color)`. Modifies
#' the `.title-slide` class. The value of this variable is also stored as a
#' CSS variable that can be referenced with `var(--title-slide-text-color)`
#' in any argument of a style function or in custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `primary_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-background-color)` in any argument of a style function
#' or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' `apply_alpha(primary_color, 0.6)`. Modifies the
#' `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' `primary_color`. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to `apply_alpha(secondary_color, 0.5)`. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #666.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #ddd. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to
#' `darken_color(choose_dark_or_light(primary_color, secondary_color, primary_color), 0.2)`.
#' Modifies the `thead, tfoot, tr:nth-child(even)` elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_duo_accent_inverse
#' @family Duotone themes
#' @export
style_duo_accent_inverse <- function(
primary_color = "#035AA6",
secondary_color = "#03A696",
white_color = "#FFFFFF",
black_color = "#000000",
text_color = white_color,
header_color = primary_color,
background_color = black_color,
link_color = choose_dark_or_light(secondary_color, secondary_color, primary_color),
text_bold_color = choose_dark_or_light(secondary_color, secondary_color, primary_color),
text_slide_number_color = primary_color,
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "rgba(255,255,0,0.5)",
code_inline_color = choose_dark_or_light(secondary_color, secondary_color, primary_color),
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = secondary_color,
inverse_text_color = choose_dark_or_light(secondary_color, black_color, white_color),
inverse_text_shadow = FALSE,
inverse_header_color = inverse_text_color,
inverse_link_color = link_color,
title_slide_text_color = choose_dark_or_light(primary_color, black_color, white_color),
title_slide_background_color = primary_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = apply_alpha(primary_color, 0.6),
left_column_selected_color = primary_color,
blockquote_left_border_color = apply_alpha(secondary_color, 0.5),
table_border_color = "#666",
table_row_border_color = "#ddd",
table_row_even_background_color = darken_color(choose_dark_or_light(primary_color, secondary_color, primary_color), 0.2),
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
primary_color <- unname(primary_color)
secondary_color <- unname(secondary_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(primary = primary_color, secondary = secondary_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan()))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_duo_accent_inverse.R |
#' Add Extra CSS Styles
#'
#' Adds css elements to target `outfile`, typically a xaringanthemer css file.
#' The `css` argument takes a list of CSS classes and definitions (see examples below)
#' and appends CSS rules to `outfile`.
#'
#' @section css list:
#' The `css` input must be a named list of css properties and values within a
#' named list of class identifiers, for example
#' `list(".class-id" = list("css-property" = "value"))`.
#'
#' @param css A named list of CSS definitions each containing a named list
#' of CSS property-value pairs, i.e.
#' `list(".class-id" = list("css-property" = "value"))`
#' @param append If `TRUE` output will be appended to `outfile`; otherwise,
#' it will overwrite the contents of `outfile`.
#' @param heading Heading added above extra CSS. Use `NULL` to disable.
#'
#' @examples
#' style_extra_css(
#' outfile = stdout(),
#' css = list(
#' ".red" = list(color = "red"),
#' ".small" = list("font-size" = "90%"),
#' ".full-width" = list(
#' display = "flex",
#' width = "100%",
#' flex = "1 1 auto"
#' )
#' )
#' )
#' @inheritParams style_xaringan
#' @export
style_extra_css <- function(
css,
outfile = "xaringan-themer.css",
append = TRUE,
heading = "Extra CSS"
) {
has_heading <- !is.null(heading)
x <- paste0(
if (has_heading) paste0("/* ", heading, " */\n"),
paste(list2css(css), collapse = "\n")
)
if (append) x <- paste0(if (has_heading) "\n\n" else "\n", x)
if (is.null(outfile)) return(x)
cat(
x,
file = outfile,
append = append,
sep = "\n"
)
invisible(x)
}
#' @inheritParams style_extra_css
#' @keywords internal
list2css <- function(css) {
`%.%` <- function(x, y) paste0(x, y)
error <- NULL
if (is.null(names(css))) {
stop("All elements in `css` list must be named", call. = FALSE)
}
if (purrr::vec_depth(css) != 3) {
stop(str_wrap(
"`css` list must be a named list within a named list, e.g.:\n",
' list(".class-id" = list("css-property" = "value"))'
))
}
if (any(names(css) == "")) {
not_named <- which(names(css) == "")
if (length(not_named) > 1) {
stop(str_wrap(
call. = FALSE,
"All elements in `css` list must be named. Items ",
paste(not_named, collapse = ", "),
" are unnamed."
))
} else {
stop(str_wrap(
call. = FALSE,
"All elements in `css` list must be named. Item ",
not_named,
" is not named."
))
}
}
child_unnamed <- purrr::map_lgl(purrr::map(css, ~ {
is.null(names(.)) || any(names(.) == "")
}), ~ any(.))
if (any(child_unnamed)) {
has_unnamed <- names(css)[child_unnamed]
msg <- paste(
"All properties of elements in `css` list must be named.",
if (length(has_unnamed) > 1) "Elements" else "Element",
paste(has_unnamed, collapse = ", "),
if (length(has_unnamed) > 1) "have" else "has",
"unnamed property or properties."
)
stop(str_wrap(msg), call. = FALSE)
}
x <- purrr::imap_chr(css, function(rules, selector) {
paste(
sep = "\n",
selector %.% " {",
paste(
purrr::imap_chr(rules, function(value, prop) {
" " %.% prop %.% ": " %.% value %.% ";"
}),
collapse = "\n"
),
"}"
)
})
unname(x)
}
list2fonts <- function(fonts) {
if (
length(setdiff(names(google_font('fam')), names(fonts))) == 0 &&
!inherits(fonts, "google_font")
) {
# concatenating a string and a google_font() provides a wacky list
stop(
"Multiple fonts in `extra_fonts` must be specified inside a `list()`.",
call. = FALSE
)
}
if (inherits(fonts, "google_font")) {
fonts <- list(fonts)
}
fonts <- purrr::map_chr(fonts, function(f) {
if (inherits(f, "google_font")) {
f$url
} else if (inherits(f, "character")) {
f
} else {
NA_character_
}
})
paste0("@import url(", fonts[!is.na(fonts)], ");")
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_extra_css.R |
#' @describeIn style_xaringan Default values for font family, weight, URLs and
#' font fallbacks.
#' @param font_arg A font argument from the \pkg{xaringanthemer} `style_`
#' function family.
#' @export
xaringanthemer_font_default <- function(font_arg) {
x <- switch(
font_arg,
text_font_family = "Noto Sans",
text_font_weight = "normal",
text_font_url = "https://fonts.googleapis.com/css?family=Noto+Sans:400,400i,700,700i&display=swap",
text_font_family_fallback = "-apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, Ubuntu, roboto, noto, segoe ui, arial",
header_font_family = "Cabin",
header_font_weight = "600",
header_font_url = "https://fonts.googleapis.com/css?family=Cabin:600,600i&display=swap",
code_font_family = "Source Code Pro",
code_font_url = "https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700&display=swap",
code_font_family_fallback = "Menlo, Consolas, Monaco, Liberation Mono, Lucida Console",
stop("unknown font_arg: ", font_arg)
)
class(x) <- c("xaringanthemer_default", class(x))
x
}
print.xaringanthemer_default <- function(x) {
print(unclass(x))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_font_default.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param base_color Monotone Base Color, works best with a strong color.
#' Defaults to #43418A. Used in multiple CSS rules. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--base)` in any argument of a style function or in custom CSS.
#' @param white_color Brightest color used. Defaults to #FFFFFF. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--white)` in any argument of a
#' style function or in custom CSS.
#' @param black_color Darkest color used. Defaults to #272822. Used in multiple
#' CSS rules. The value of this variable is also stored as a CSS variable
#' that can be referenced with `var(--black)` in any argument of a style
#' function or in custom CSS.
#' @param text_color Text Color. Defaults to `black_color`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text_color)` in any argument of a style
#' function or in custom CSS.
#' @param header_color Header Color. Defaults to `base_color`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-color)` in any argument
#' of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to `white_color`.
#' Modifies the `.remark-slide-content` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to `base_color`. Modifies the
#' `a, a > code` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--link-color)` in any argument
#' of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to `base_color`. Modifies
#' the `strong` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-bold-color)` in any
#' argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to `base_color`.
#' Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to
#' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
#' The value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--code-highlight-color)` in any argument of a style
#' function or in custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to `base_color`.
#' Modifies the `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' `base_color`. Modifies the `.inverse` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to `white_color`.
#' Modifies the `.inverse` class. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--inverse-text-color)`
#' in any argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to
#' `inverse_text_color`. Modifies the `.inverse h1, .inverse h2, .inverse h3`
#' classes. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--inverse-header-color)` in any argument of a
#' style function or in custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `inverse_text_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-text-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `inverse_background_color`. Modifies the `.title-slide` class. The
#' value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--title-slide-background-color)` in any argument of a
#' style function or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' `apply_alpha(base_color, 0.6)`. Modifies the
#' `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' `base_color`. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to `apply_alpha(base_color, 0.5)`. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #666.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #ddd. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to `lighten_color(base_color, 0.8)`. Modifies the
#' `thead, tfoot, tr:nth-child(even)` elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_mono_accent
#' @family Monotone themes
#' @export
style_mono_accent <- function(
base_color = "#43418A",
white_color = "#FFFFFF",
black_color = "#272822",
text_color = black_color,
header_color = base_color,
background_color = white_color,
link_color = base_color,
text_bold_color = base_color,
text_slide_number_color = base_color,
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "rgba(255,255,0,0.5)",
code_inline_color = base_color,
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = base_color,
inverse_text_color = white_color,
inverse_text_shadow = FALSE,
inverse_header_color = inverse_text_color,
inverse_link_color = link_color,
title_slide_text_color = inverse_text_color,
title_slide_background_color = inverse_background_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = apply_alpha(base_color, 0.6),
left_column_selected_color = base_color,
blockquote_left_border_color = apply_alpha(base_color, 0.5),
table_border_color = "#666",
table_row_border_color = "#ddd",
table_row_even_background_color = lighten_color(base_color, 0.8),
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
base_color <- unname(base_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(base = base_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan()))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_mono_accent.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param base_color Monotone Base Color, works best with a light color.
#' Defaults to #3C989E. Used in multiple CSS rules. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--base)` in any argument of a style function or in custom CSS.
#' @param white_color Brightest color used, default is a very light version of
#' `base_color`. Defaults to #FFFFFF. Used in multiple CSS rules. The value
#' of this variable is also stored as a CSS variable that can be referenced
#' with `var(--white)` in any argument of a style function or in custom CSS.
#' @param black_color Darkest color used, default is a very dark, version of
#' `base_color`. Defaults to `darken_color(base_color, 0.9)`. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--black)` in any argument of a
#' style function or in custom CSS.
#' @param text_color Text Color. Defaults to `white_color`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text_color)` in any argument of a style
#' function or in custom CSS.
#' @param header_color Header Color. Defaults to `base_color`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-color)` in any argument
#' of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to `black_color`.
#' Modifies the `.remark-slide-content` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to `base_color`. Modifies the
#' `a, a > code` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--link-color)` in any argument
#' of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to `base_color`. Modifies
#' the `strong` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-bold-color)` in any
#' argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to `base_color`.
#' Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to
#' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
#' The value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--code-highlight-color)` in any argument of a style
#' function or in custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to `base_color`.
#' Modifies the `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' `base_color`. Modifies the `.inverse` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to `black_color`.
#' Modifies the `.inverse` class. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--inverse-text-color)`
#' in any argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to
#' `inverse_text_color`. Modifies the `.inverse h1, .inverse h2, .inverse h3`
#' classes. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--inverse-header-color)` in any argument of a
#' style function or in custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `inverse_text_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-text-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `inverse_background_color`. Modifies the `.title-slide` class. The
#' value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--title-slide-background-color)` in any argument of a
#' style function or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' `apply_alpha(base_color, 0.6)`. Modifies the
#' `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' `base_color`. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to `apply_alpha(base_color, 0.5)`. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #666.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #ddd. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to `darken_color(base_color, 0.8)`. Modifies the
#' `thead, tfoot, tr:nth-child(even)` elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_mono_accent_inverse
#' @family Monotone themes
#' @export
style_mono_accent_inverse <- function(
base_color = "#3C989E",
white_color = "#FFFFFF",
black_color = darken_color(base_color, 0.9),
text_color = white_color,
header_color = base_color,
background_color = black_color,
link_color = base_color,
text_bold_color = base_color,
text_slide_number_color = base_color,
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "rgba(255,255,0,0.5)",
code_inline_color = base_color,
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = base_color,
inverse_text_color = black_color,
inverse_text_shadow = FALSE,
inverse_header_color = inverse_text_color,
inverse_link_color = link_color,
title_slide_text_color = inverse_text_color,
title_slide_background_color = inverse_background_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = apply_alpha(base_color, 0.6),
left_column_selected_color = base_color,
blockquote_left_border_color = apply_alpha(base_color, 0.5),
table_border_color = "#666",
table_row_border_color = "#ddd",
table_row_even_background_color = darken_color(base_color, 0.8),
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
base_color <- unname(base_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(base = base_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan()))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_mono_accent_inverse.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param base_color Monotone Base Color, works best with a light color..
#' Defaults to #cbf7ed. Used in multiple CSS rules. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--base)` in any argument of a style function or in custom CSS.
#' @param white_color Brightest color used, default is a very light version of
#' `base_color`. Defaults to `lighten_color(base_color, 0.8)`. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--white)` in any argument of a
#' style function or in custom CSS.
#' @param black_color Darkest color used, default is a very dark, version of
#' `base_color`. Defaults to `darken_color(base_color, 0.85)`. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--black)` in any argument of a
#' style function or in custom CSS.
#' @param text_color Text Color. Defaults to `white_color`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text_color)` in any argument of a style
#' function or in custom CSS.
#' @param header_color Header Color. Defaults to `base_color`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-color)` in any argument
#' of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to `black_color`.
#' Modifies the `.remark-slide-content` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to `base_color`. Modifies the
#' `a, a > code` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--link-color)` in any argument
#' of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to `base_color`. Modifies
#' the `strong` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-bold-color)` in any
#' argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to `base_color`.
#' Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to
#' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
#' The value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--code-highlight-color)` in any argument of a style
#' function or in custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to `base_color`.
#' Modifies the `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' `base_color`. Modifies the `.inverse` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to `black_color`.
#' Modifies the `.inverse` class. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--inverse-text-color)`
#' in any argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to
#' `inverse_text_color`. Modifies the `.inverse h1, .inverse h2, .inverse h3`
#' classes. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--inverse-header-color)` in any argument of a
#' style function or in custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `inverse_text_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-text-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `inverse_background_color`. Modifies the `.title-slide` class. The
#' value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--title-slide-background-color)` in any argument of a
#' style function or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' `apply_alpha(base_color, 0.6)`. Modifies the
#' `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' `base_color`. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to `apply_alpha(base_color, 0.5)`. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #666.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #ddd. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to `darken_color(base_color, 0.7)`. Modifies the
#' `thead, tfoot, tr:nth-child(even)` elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_mono_dark
#' @family Monotone themes
#' @export
style_mono_dark <- function(
base_color = "#cbf7ed",
white_color = lighten_color(base_color, 0.8),
black_color = darken_color(base_color, 0.85),
text_color = white_color,
header_color = base_color,
background_color = black_color,
link_color = base_color,
text_bold_color = base_color,
text_slide_number_color = base_color,
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "rgba(255,255,0,0.5)",
code_inline_color = base_color,
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = base_color,
inverse_text_color = black_color,
inverse_text_shadow = FALSE,
inverse_header_color = inverse_text_color,
inverse_link_color = link_color,
title_slide_text_color = inverse_text_color,
title_slide_background_color = inverse_background_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = apply_alpha(base_color, 0.6),
left_column_selected_color = base_color,
blockquote_left_border_color = apply_alpha(base_color, 0.5),
table_border_color = "#666",
table_row_border_color = "#ddd",
table_row_even_background_color = darken_color(base_color, 0.7),
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
base_color <- unname(base_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(base = base_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan()))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_mono_dark.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param base_color Monotone base color, works best with a strong color.
#' Defaults to #23395b. Used in multiple CSS rules. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--base)` in any argument of a style function or in custom CSS.
#' @param white_color Brightest color used, default is a very light version of
#' `base_color`. Defaults to `lighten_color(base_color, 0.9)`. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--white)` in any argument of a
#' style function or in custom CSS.
#' @param black_color Darkest color used, default is a very dark, version of
#' `base_color`. Defaults to `darken_color(base_color, 0.3)`. Used in
#' multiple CSS rules. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--black)` in any argument of a
#' style function or in custom CSS.
#' @param text_color Text Color. Defaults to `black_color`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text_color)` in any argument of a style
#' function or in custom CSS.
#' @param header_color Header Color. Defaults to `base_color`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-color)` in any argument
#' of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to `white_color`.
#' Modifies the `.remark-slide-content` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to `base_color`. Modifies the
#' `a, a > code` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--link-color)` in any argument
#' of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to `base_color`. Modifies
#' the `strong` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-bold-color)` in any
#' argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to `base_color`.
#' Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to
#' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
#' The value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--code-highlight-color)` in any argument of a style
#' function or in custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to `base_color`.
#' Modifies the `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' `base_color`. Modifies the `.inverse` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to `white_color`.
#' Modifies the `.inverse` class. The value of this variable is also stored
#' as a CSS variable that can be referenced with `var(--inverse-text-color)`
#' in any argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to
#' `inverse_text_color`. Modifies the `.inverse h1, .inverse h2, .inverse h3`
#' classes. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--inverse-header-color)` in any argument of a
#' style function or in custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `inverse_text_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-text-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `inverse_background_color`. Modifies the `.title-slide` class. The
#' value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--title-slide-background-color)` in any argument of a
#' style function or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' `apply_alpha(base_color, 0.6)`. Modifies the
#' `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' `base_color`. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to `apply_alpha(base_color, 0.5)`. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #666.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #ddd. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to `lighten_color(base_color, 0.8)`. Modifies the
#' `thead, tfoot, tr:nth-child(even)` elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_mono_light
#' @family Monotone themes
#' @export
style_mono_light <- function(
base_color = "#23395b",
white_color = lighten_color(base_color, 0.9),
black_color = darken_color(base_color, 0.3),
text_color = black_color,
header_color = base_color,
background_color = white_color,
link_color = base_color,
text_bold_color = base_color,
text_slide_number_color = base_color,
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "rgba(255,255,0,0.5)",
code_inline_color = base_color,
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = base_color,
inverse_text_color = white_color,
inverse_text_shadow = FALSE,
inverse_header_color = inverse_text_color,
inverse_link_color = link_color,
title_slide_text_color = inverse_text_color,
title_slide_background_color = inverse_background_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = apply_alpha(base_color, 0.6),
left_column_selected_color = base_color,
blockquote_left_border_color = apply_alpha(base_color, 0.5),
table_border_color = "#666",
table_row_border_color = "#ddd",
table_row_even_background_color = lighten_color(base_color, 0.8),
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
base_color <- unname(base_color)
white_color <- unname(white_color)
black_color <- unname(black_color)
colors <- c(base = base_color, white = white_color, black = black_color, colors)
eval(parse(text = call_style_xaringan()))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_mono_light.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param text_color Text Color. Defaults to #839496. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text_color)` in any argument of a style
#' function or in custom CSS.
#' @param header_color Header Color. Defaults to #dc322f. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-color)` in any argument
#' of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to #002b36.
#' Modifies the `.remark-slide-content` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to #b58900. Modifies the
#' `a, a > code` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--link-color)` in any argument
#' of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to #d33682. Modifies the
#' `strong` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-bold-color)` in any
#' argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to #586e75.
#' Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to #268bd240.
#' Modifies the `.remark-code-line-highlighted` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--code-highlight-color)` in any argument of a style function or in
#' custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to #6c71c4. Modifies
#' the `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' #fdf6e3. Modifies the `.inverse` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to #002b36. Modifies
#' the `.inverse` class. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--inverse-text-color)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to
#' `inverse_text_color`. Modifies the `.inverse h1, .inverse h2, .inverse h3`
#' classes. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--inverse-header-color)` in any argument of a
#' style function or in custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `inverse_text_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-text-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `inverse_background_color`. Modifies the `.title-slide` class. The
#' value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--title-slide-background-color)` in any argument of a
#' style function or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' #586e75. Modifies the `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' #93a1a1. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to #cb4b16. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #657b83.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #657b83. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to #073642. Modifies the `thead, tfoot, tr:nth-child(even)`
#' elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_solarized_dark
#' @family Solarized themes
#' @export
style_solarized_dark <- function(
text_color = "#839496",
header_color = "#dc322f",
background_color = "#002b36",
link_color = "#b58900",
text_bold_color = "#d33682",
text_slide_number_color = "#586e75",
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "#268bd240",
code_inline_color = "#6c71c4",
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = "#fdf6e3",
inverse_text_color = "#002b36",
inverse_text_shadow = FALSE,
inverse_header_color = inverse_text_color,
inverse_link_color = link_color,
title_slide_text_color = inverse_text_color,
title_slide_background_color = inverse_background_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = "#586e75",
left_column_selected_color = "#93a1a1",
blockquote_left_border_color = "#cb4b16",
table_border_color = "#657b83",
table_row_border_color = "#657b83",
table_row_even_background_color = "#073642",
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
eval(parse(text = call_style_xaringan()))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_solarized_dark.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param text_color Text Color. Defaults to #657b83. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text_color)` in any argument of a style
#' function or in custom CSS.
#' @param header_color Header Color. Defaults to #dc322f. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-color)` in any argument
#' of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to #fdf6e3.
#' Modifies the `.remark-slide-content` class. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to #b58900. Modifies the
#' `a, a > code` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--link-color)` in any argument
#' of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to #d33682. Modifies the
#' `strong` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-bold-color)` in any
#' argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to #93a1a1.
#' Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to #268bd240.
#' Modifies the `.remark-code-line-highlighted` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--code-highlight-color)` in any argument of a style function or in
#' custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to #6c71c4. Modifies
#' the `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' #002b36. Modifies the `.inverse` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to #fdf6e3. Modifies
#' the `.inverse` class. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--inverse-text-color)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to
#' `inverse_text_color`. Modifies the `.inverse h1, .inverse h2, .inverse h3`
#' classes. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--inverse-header-color)` in any argument of a
#' style function or in custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `inverse_text_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-text-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `inverse_background_color`. Modifies the `.title-slide` class. The
#' value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--title-slide-background-color)` in any argument of a
#' style function or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' #93a1a1. Modifies the `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' #586e75. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to #cb4b16. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #839496.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #839496. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to #eee8d5. Modifies the `thead, tfoot, tr:nth-child(even)`
#' elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_solarized_light
#' @family Solarized themes
#' @export
style_solarized_light <- function(
text_color = "#657b83",
header_color = "#dc322f",
background_color = "#fdf6e3",
link_color = "#b58900",
text_bold_color = "#d33682",
text_slide_number_color = "#93a1a1",
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "#268bd240",
code_inline_color = "#6c71c4",
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = "#002b36",
inverse_text_color = "#fdf6e3",
inverse_text_shadow = FALSE,
inverse_header_color = inverse_text_color,
inverse_link_color = link_color,
title_slide_text_color = inverse_text_color,
title_slide_background_color = inverse_background_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = "#93a1a1",
left_column_selected_color = "#586e75",
blockquote_left_border_color = "#cb4b16",
table_border_color = "#839496",
table_row_border_color = "#839496",
table_row_even_background_color = "#eee8d5",
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
eval(parse(text = call_style_xaringan()))
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_solarized_light.R |
# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
#' @param text_color Text Color. Defaults to #000. Modifies the `body` element.
#' The value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--text_color)` in any argument of a style function or
#' in custom CSS.
#' @param header_color Header Color. Defaults to #000. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-color)` in any argument
#' of a style function or in custom CSS.
#' @param background_color Slide Background Color. Defaults to #FFF. Modifies
#' the `.remark-slide-content` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--background-color)` in any argument of a style function or in custom
#' CSS.
#' @param link_color Link Color. Defaults to rgb(249, 38, 114). Modifies the
#' `a, a > code` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--link-color)` in any argument
#' of a style function or in custom CSS.
#' @param text_bold_color Bold Text Color. Defaults to `NULL`. Modifies the
#' `strong` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-bold-color)` in any
#' argument of a style function or in custom CSS.
#' @param text_slide_number_color Slide Number Color. Defaults to
#' `inverse_background_color`. Modifies the `.remark-slide-number` class.
#' @param padding Slide Padding in `top right [bottom left]` format. Defaults
#' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
#' Accepts CSS
#' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param background_image Background image applied to each *and every* slide.
#' Set `title_slide_background_image = "none"` to remove the background image
#' from the title slide. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class.
#' @param background_size Background image size, requires `background_image` to
#' be set. If `background_image` is set, `background_size` will default to
#' `cover` so the background fills the screen. If both `background_image` and
#' `background_position` are set, will default to 100 percent. Defaults to
#' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param background_position Background image position, requires
#' `background_image` to be set, and it is recommended to adjust
#' `background_size`. Defaults to `NULL`. Modifies the
#' `.remark-slide-content` class. Accepts CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param code_highlight_color Code Line Highlight. Defaults to
#' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
#' The value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--code-highlight-color)` in any argument of a style
#' function or in custom CSS.
#' @param code_inline_color Inline Code Color. Defaults to #000. Modifies the
#' `.remark-inline-code` class.
#' @param code_inline_background_color Inline Code Background Color. Defaults
#' to `NULL`. Modifies the `.remark-inline-code` class.
#' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
#' Modifies the `.remark-inline-code` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-inline-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_background_color Inverse Background Color. Defaults to
#' #272822. Modifies the `.inverse` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--inverse-background-color)` in any argument of a style function or
#' in custom CSS.
#' @param inverse_text_color Inverse Text Color. Defaults to #d6d6d6. Modifies
#' the `.inverse` class. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--inverse-text-color)` in any
#' argument of a style function or in custom CSS.
#' @param inverse_text_shadow Enables Shadow on text of inverse slides.
#' Defaults to `FALSE`. Modifies the `.inverse` class.
#' @param inverse_header_color Inverse Header Color. Defaults to #f3f3f3.
#' Modifies the `.inverse h1, .inverse h2, .inverse h3` classes. The value of
#' this variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-header-color)` in any argument of a style function or in
#' custom CSS.
#' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
#' Modifies the `.inverse a, .inverse a > code` classes. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--inverse-link-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_text_color Title Slide Text Color. Defaults to
#' `inverse_text_color`. Modifies the `.title-slide` class. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--title-slide-text-color)` in any argument of a style function or in
#' custom CSS.
#' @param title_slide_background_color Title Slide Background Color. Defaults
#' to `inverse_background_color`. Modifies the `.title-slide` class. The
#' value of this variable is also stored as a CSS variable that can be
#' referenced with `var(--title-slide-background-color)` in any argument of a
#' style function or in custom CSS.
#' @param title_slide_background_image Title Slide Background Image URL.
#' Defaults to `NULL`. Modifies the `.title-slide` class.
#' @param title_slide_background_size Title Slide Background Image Size,
#' defaults to "cover" if background image is set. Defaults to `NULL`.
#' Modifies the `.title-slide` class. Accepts CSS
#' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
#' property values.
#' @param title_slide_background_position Title Slide Background Image
#' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
#' CSS
#' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
#' property values.
#' @param footnote_color Footnote text color (if `NA`, then it will be the same
#' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
#' class.
#' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
#' the `.footnote` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param footnote_position_bottom Footnote location from bottom of screen.
#' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
#' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
#' property values.
#' @param left_column_subtle_color Left Column Text (not last). Defaults to
#' #777. Modifies the `.left-column h2, .left-column h3` classes.
#' @param left_column_selected_color Left Column Current Selection. Defaults to
#' #000. Modifies the
#' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
#' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
#' to lightgray. Modifies the `blockquote` element.
#' @param table_border_color Table top/bottom border. Defaults to #666.
#' Modifies the `table: border-top, border-bottom` elements.
#' @param table_row_border_color Table row inner bottom border. Defaults to
#' #ddd. Modifies the `table thead th: border-bottom` elements.
#' @param table_row_even_background_color Table Even Row Background Color.
#' Defaults to #eee. Modifies the `thead, tfoot, tr:nth-child(even)`
#' elements.
#' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
#' Defaults to 20px. Modifies the `html` element. The value of this variable
#' is also stored as a CSS variable that can be referenced with
#' `var(--base-font-size)` in any argument of a style function or in custom
#' CSS.
#' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
#' the `.remark-slide-content` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
#' Modifies the `.remark-slide-content h1` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h1-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
#' Modifies the `.remark-slide-content h2` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h2-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
#' Modifies the `.remark-slide-content h3` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-h3-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param header_background_auto Add background under slide title automatically
#' for h1 header elements. If not enabled, use `class: header_background` to
#' enable. Defaults to `FALSE`.
#' @param header_background_color Background Color for h1 Header with
#' Background. Defaults to `header_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-color)` in any argument of a style function or in
#' custom CSS.
#' @param header_background_text_color Text Color for h1 Header with
#' Background. Defaults to `background_color`. Modifies the
#' `.remark-slide-content h1` class. The value of this variable is also
#' stored as a CSS variable that can be referenced with
#' `var(--header-background-text-color)` in any argument of a style function
#' or in custom CSS.
#' @param header_background_padding Padding for h1 Header with Background.
#' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
#' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
#' property values.
#' @param header_background_content_padding_top Top Padding for Content in
#' Slide with Header with Background. Defaults to 7rem. Modifies the
#' `.remark-slide-content` class.
#' @param header_background_ignore_classes Slide Classes Where Header with
#' Background will not be Applied. Defaults to
#' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
#' `.remark-slide-content` class.
#' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
#' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values.
#' @param text_font_google Use `google_font()` to specify body font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param text_font_family Body Text Font Family (xaringan default is
#' `'Droid Serif'`). Defaults to
#' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
#' element. The value of this variable is also stored as a CSS variable that
#' can be referenced with `var(--text-font-family)` in any argument of a
#' style function or in custom CSS.
#' @param text_font_weight Body Text Font Weight. Defaults to
#' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
#' element. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
#' Modifies the `strong` element.
#' @param text_font_url Body Text Font URL(s). Defaults to
#' `xaringanthemer_font_default("text_font_url")`. Modifies the
#' `@import url()` elements.
#' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
#' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
#' `body` element. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--text-font-family-fallback)` in
#' any argument of a style function or in custom CSS.
#' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
#' to sans-serif. Modifies the `body` element. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--text-font-base)` in any argument of a style function or in custom
#' CSS.
#' @param header_font_google Use `google_font()` to specify header font.
#' Defaults to `NULL`. Modifies the `body` element.
#' @param header_font_family Header Font Family (xaringan default is
#' `'Yanone Kaffeesatz'`). Defaults to
#' `xaringanthemer_font_default("header_font_family")`. Modifies the
#' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--header-font-family)` in any
#' argument of a style function or in custom CSS.
#' @param header_font_weight Header Font Weight. Defaults to
#' `xaringanthemer_font_default("header_font_weight")`. Modifies the
#' `h1, h2, h3` elements. Accepts CSS
#' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
#' property values.
#' @param header_font_family_fallback Header Font Family Fallback. Defaults to
#' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
#' variable is also stored as a CSS variable that can be referenced with
#' `var(--header-font-family-fallback)` in any argument of a style function
#' or in custom CSS.
#' @param header_font_url Header Font URL. Defaults to
#' `xaringanthemer_font_default("header_font_url")`. Modifies the
#' `@import url` elements.
#' @param code_font_google Use `google_font()` to specify code font. Defaults
#' to `NULL`. Modifies the `body` element.
#' @param code_font_family Code Font Family. Defaults to
#' `xaringanthemer_font_default("code_font_family")`. Modifies the
#' `.remark-code, .remark-inline-code` classes. The value of this variable is
#' also stored as a CSS variable that can be referenced with
#' `var(--code-font-family)` in any argument of a style function or in custom
#' CSS.
#' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
#' `.remark-inline` class. Accepts CSS
#' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
#' property values. The value of this variable is also stored as a CSS
#' variable that can be referenced with `var(--code-font-size)` in any
#' argument of a style function or in custom CSS.
#' @param code_font_url Code Font URL. Defaults to
#' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
#' elements.
#' @param code_font_family_fallback Code Font Fallback. Defaults to
#' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
#' `.remark-code, .remark-inline-code` classes.
#' @param link_decoration Text decoration of links. Defaults to none. Modifies
#' the `a, a > code` elements. Accepts CSS
#' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
#' property values.
#' @template theme_params
#' @template style-usage
#' @template style_xaringan
#' @export
style_xaringan <- function(
text_color = "#000",
header_color = "#000",
background_color = "#FFF",
link_color = "rgb(249, 38, 114)",
text_bold_color = NULL,
text_slide_number_color = inverse_background_color,
padding = "16px 64px 16px 64px",
background_image = NULL,
background_size = NULL,
background_position = NULL,
code_highlight_color = "rgba(255,255,0,0.5)",
code_inline_color = "#000",
code_inline_background_color = NULL,
code_inline_font_size = "1em",
inverse_background_color = "#272822",
inverse_text_color = "#d6d6d6",
inverse_text_shadow = FALSE,
inverse_header_color = "#f3f3f3",
inverse_link_color = link_color,
title_slide_text_color = inverse_text_color,
title_slide_background_color = inverse_background_color,
title_slide_background_image = NULL,
title_slide_background_size = NULL,
title_slide_background_position = NULL,
footnote_color = NULL,
footnote_font_size = "0.9em",
footnote_position_bottom = "60px",
left_column_subtle_color = "#777",
left_column_selected_color = "#000",
blockquote_left_border_color = "lightgray",
table_border_color = "#666",
table_row_border_color = "#ddd",
table_row_even_background_color = "#eee",
base_font_size = "20px",
text_font_size = "1rem",
header_h1_font_size = "2.75rem",
header_h2_font_size = "2.25rem",
header_h3_font_size = "1.75rem",
header_background_auto = FALSE,
header_background_color = header_color,
header_background_text_color = background_color,
header_background_padding = NULL,
header_background_content_padding_top = "7rem",
header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
text_slide_number_font_size = "0.9rem",
text_font_google = NULL,
text_font_family = xaringanthemer_font_default("text_font_family"),
text_font_weight = xaringanthemer_font_default("text_font_weight"),
text_bold_font_weight = "bold",
text_font_url = xaringanthemer_font_default("text_font_url"),
text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
text_font_base = "sans-serif",
header_font_google = NULL,
header_font_family = xaringanthemer_font_default("header_font_family"),
header_font_weight = xaringanthemer_font_default("header_font_weight"),
header_font_family_fallback = "Georgia, serif",
header_font_url = xaringanthemer_font_default("header_font_url"),
code_font_google = NULL,
code_font_family = xaringanthemer_font_default("code_font_family"),
code_font_size = "0.9rem",
code_font_url = xaringanthemer_font_default("code_font_url"),
code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
link_decoration = "none",
colors = NULL,
extra_css = NULL,
extra_fonts = NULL,
outfile = "xaringan-themer.css"
) {
# DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
force(text_font_family)
force(text_font_weight)
force(text_font_url)
force(text_font_family_fallback)
force(header_font_family)
force(header_font_weight)
force(header_font_url)
force(code_font_family)
force(code_font_url)
force(code_font_family_fallback)
# the defaults are google fonts
is_default <- function(type, suffix) {
# check if font arg value is from xaringanthemer_font_default
var <- paste0(type, "_", suffix)
inherits(
get(var, envir = parent.frame(2), inherits = FALSE),
"xaringanthemer_default"
)
}
for (var in c("text", "header", "code")) {
suffixes <- c("font_family", "font_weight", "font_url")
if (var == "code") suffixes <- setdiff(suffixes, "font_weight")
var_is_google <- all(vapply(suffixes, is_default, logical(1), type = var))
var_is_google <- as.integer(var_is_google)
r_set_font_is_google <- glue::glue("{var}_font_is_google <- {var_is_google}")
eval(parse(text = r_set_font_is_google))
}
# Make sure font names are wrapped in quotes if they have spaces
f_args <- names(formals(sys.function()))
for (var in f_args[grepl("font_family$", f_args)]) {
var_value <- get(var, inherits = FALSE)
if (!is.null(var_value)) {
eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")")))
}
}
# Warn if base_font_size isn't absolute
css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px")
if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) {
warning(
glue::glue(
"Base font size '{base_font_size}' is not in absolute units. ",
"For best results, specify the `base_font_size` using absolute CSS units: ",
"{paste(css_abs_units, collapse = ', ')}"
),
call. = FALSE,
immediate. = TRUE
)
}
# If certain colors aren't in hexadecimal it may cause problems with theme_xaringan()
# TODO: at some point I'd rather be able to process CSS colors or variables
colors_used_by_theme_xaringan <- list(
background_color = background_color,
text_color = text_color,
header_color = header_color,
text_bold_color = text_bold_color,
inverse_background_color = inverse_background_color,
inverse_text_color = inverse_text_color,
inverse_header_color = inverse_header_color
)
colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null)
colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL)
if (any(!colors_are_hex)) {
colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex]
colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ")
warning(
glue::glue("Colors that will be used by `theme_xaringan()` need to be in ",
"hexadecimal format: {colors_better_as_hex}"),
immediate. = TRUE,
call. = FALSE
)
}
# Use font_..._google args to overwrite font args
for (var in f_args[grepl("font_google$", f_args)]) {
gf <- eval(parse(text = var))
if (is.null(gf)) next
if (!inherits(gf, "google_font")) {
stop("`", var, "` must be set using `google_font()`.")
}
group <- strsplit(var, "_")[[1]][1]
if (group == "text") {
text_font_family <- quote_elements_w_spaces(gf$family)
text_font_weight <- gf$weights %||% "normal"
if (grepl(",", text_font_weight)) {
# Use first font weight if multiple are imported
text_font_weight <- substr(text_font_weight, 1, regexpr(",", text_font_weight)[1] - 1)
}
text_font_url <- gf$url
} else {
eval(parse(text = paste0(group, "_font_family <- quote_elements_w_spaces(gf$family)")))
eval(parse(text = paste0(group, "_font_url <- gf$url")))
}
eval(parse(text = paste0(group, "_font_is_google <- 1")))
}
extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts)
extra_font_imports <- paste(extra_font_imports, collapse = "\n")
# convert NA arguments to NULL
for (var in f_args) {
val <- eval(parse(text = var))
if (is.null(val)) next
val <- val[!is.na(val)]
is_na <- length(val) == 0
if (is_na) assign(var, NULL, envir = sys.frame(sys.nframe()))
}
# prepare variables for template
body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ")
background_size_fallback <- if (is.null(background_position)) "cover" else "100%"
background_size <- background_image %??% (background_size %||% background_size_fallback)
title_slide_background_size <- title_slide_background_size %||% (
title_slide_background_image %??% "cover"
)
table_row_even_background_color <- table_row_even_background_color %||% background_color
# stash theme settings in package env
lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env))
for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) {
assign(
font_is_google,
get(font_is_google, inherits = FALSE) == 1,
envir = xaringanthemer_env
)
}
xaringanthemer_version <- utils::packageVersion("xaringanthemer")
# prepare header background object
needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes)
header_background_ignore_classes[needs_leading_dot] <- paste0(
".",
header_background_ignore_classes[needs_leading_dot]
)
header_background_ignore_classes <- purrr::map(
header_background_ignore_classes,
~ list(class = .)
)
if (is.null(header_background_padding)) {
slide_padding <- css_get_padding(padding)
header_background_padding <- paste(
"2rem", slide_padding$right, "1.5rem", slide_padding$left
)
}
header_background <- list(
auto = header_background_auto,
background_color = header_background_color,
text_color = header_background_text_color,
padding = header_background_padding,
content_padding_top = header_background_content_padding_top,
ignore = header_background_ignore_classes
)
colors <- prepare_colors(colors)
tf <- system.file("resources", "template.css", package = "xaringanthemer")
template <- readLines(tf, warn = FALSE)
template <- paste(template, collapse = "\n")
x <- whisker::whisker.render(template)
if (!is.null(extra_css)) {
x <- c(x, style_extra_css(extra_css, outfile = NULL))
}
if (is.null(outfile)) {
return(x)
}
writeLines(x, con = outfile)
invisible(outfile)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/style_xaringan.R |
`%||%` <- function(x, y) if (is.null(x)) y else x
`%??%` <- function(x, y) if (!is.null(x)) y else NULL
requires_package <- function(pkg = "ggplot2", fn = "", required = TRUE) {
raise <- if (required) stop else warning
if (!requireNamespace(pkg, quietly = TRUE)) {
msg <- paste0(
"`",
pkg,
"` is ",
if (required) "required " else "suggested ",
if (fn != "") paste0("by ", fn, "() ")[1],
"but is not installed."
)
raise(msg, call. = FALSE)
return(invisible(FALSE))
}
invisible(TRUE)
}
#' @keywords internal
call_style_xaringan <- function() {
paste0(
"style_xaringan(",
paste(names(formals(style_xaringan)), collapse = ", "),
")"
)
}
#' Specify Google Font
#'
#' Builds Google Fonts URL from family name. Extra weights are given in the
#' `...` parameters. Languages can be specified in `languages` and must one or
#' more of the language codes as given by `google_language_codes()`.
#'
#' @examples
#' google_font("Josefin Sans", "400", "400i", "600i", "700")
#' google_font("Josefin Sans", languages = c("latin-ext", "vietnamese"))
#' @param family Font family
#' @param ... Font weights to include, example "400", "400i"
#' @param languages Font languages to include (dependent on the font.) See
#' [google_language_codes()].
#' @return A `"google_font"` object.
#' @export
google_font <- function(family, ..., languages = NULL) {
base <- "https://fonts.googleapis.com/css?family="
weights <- if (length(list(...))) paste(c(...), collapse = ",")
languages <- if (!is.null(languages)) paste(google_language_codes(languages), collapse = ",")
structure(
list(
family = family,
weights = weights,
languages = languages,
url = paste0(
base,
gsub(" ", "+", family),
if (!is.null(weights)) paste0(":", weights),
if (!is.null(languages)) paste0("&subset=", languages),
"&display=swap"
)
),
class = "google_font"
)
}
is_google_font <- function(x) inherits(x, "google_font")
#' @title List Valid Google Language Codes
#' @description Gives a list of valid Language Codes for Google Fonts, or
#' validates that the language codes given are valid.
#' @seealso [google_font()]
#' @param language_codes Vector of potential Google language codes
#' @return A vector of Google Font language codes matching `language_codes`.
#' @export
google_language_codes <- function(
language_codes = c(
"latin",
"latin-ext",
"sinhala",
"greek",
"hebrew",
"vietnamese",
"cyrillic",
"cyrillic-ext",
"devanagari",
"arabic",
"khmer",
"tamil",
"greek-ext",
"thai",
"bengali",
"gujarati",
"oriya",
"malayalam",
"gurmukhi",
"kannada",
"telugu",
"myanmar"
)) {
unique(match.arg(language_codes, several.ok = TRUE))
}
print.google_font <- function(x) {
cat(
"Family: ",
x$family,
if (!is.null(x$weights)) paste("\nWeights:", x$weights),
if (!is.null(x$languages)) paste("\nLangs: ", x$languages),
"\nURL: ",
x$url
)
}
quote_elements_w_spaces <- function(x) {
x <- strsplit(x, ", ?")[[1]]
has_space <- grepl("\\w \\w", x)
not_quoted <- grepl("^\\w.+\\w$", x)
x[has_space & not_quoted] <- paste0("'", x[has_space & not_quoted], "'")
paste(x, collapse = ", ")
}
str_wrap <- function(...) {
paste(strwrap(paste0(...)), collapse = "\n")
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/utils.R |
# nocov start
# Theme Generating Helpers ----------------------------------------------
plural_element <- function(css_name) {
is_mult <- grepl(",|and|or", css_name)
is_class <- grepl("^\\.", css_name)
ifelse(is_class,
ifelse(is_mult, "classes", "class"),
ifelse(is_mult, "elements", "element")
)
}
element_description <- function(element) {
out <- rep("", length(element))
multiple <- grepl("multiple", element)
out[multiple] <- "Used in multiple CSS rules."
ifelse(
multiple | is.na(element) | element == "",
out,
glue::glue("Modifies the `{element}` {plural_element(element)}.")
)
}
describe_css_variable <- function(css_variable = NULL) {
if (is.null(css_variable)) return("")
ifelse(
is.na(css_variable),
"",
glue::glue(
" The value of this variable is also stored as a CSS variable that can be ",
"referenced with `var({css_variable})` in any argument of a style ",
"function or in custom CSS."
)
)
}
describe_css_property <- function(css_property = NULL) {
if (is.null(css_property)) return("")
ifelse(
is.na(css_property),
"",
glue::glue(" Accepts CSS {css_property} property values.")
)
}
# nocov end
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/utils_theme-gen.R |
#' Deprecated or renamed functions
#'
#' These functions in xaringanthemer have been deprecated or renamed.
#'
#' @param ... Argumets passed to the new or renamed functions.
#' @return The result of the new or renamed function.
#' @name xaringanthemer-deprecated
NULL
#' @description
#' Use [style_xaringan()] instead of `write_xaringan_theme()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
write_xaringan_theme <- function(...) {
.Deprecated(msg = "write_xaringan_theme() was renamed. Please use `style_xaringan()` instead.")
style_xaringan(...)
}
#' @description
#' Use [style_extra_css()] instead of `write_extra_css()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
write_extra_css <- function(...) {
.Deprecated(msg = "write_extra_css() was renamed. Please use `style_extra_css()` instead.")
style_extra_css(...)
}
#' @description
#' Use [style_mono_light()] instead of `mono_light()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
mono_light <- function(...) {
.Deprecated(msg = "mono_light() was renamed. Please use `style_mono_light()` instead.")
style_mono_light(...)
}
#' @description
#' Use [style_mono_dark()] instead of `mono_dark()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
mono_dark <- function(...) {
.Deprecated(msg = "mono_dark() was renamed. Please use `style_mono_dark()` instead.")
style_mono_dark(...)
}
#' @description
#' Use [style_mono_accent()] instead of `mono_accent()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
mono_accent <- function(...) {
.Deprecated(msg = "mono_accent() was renamed. Please use `style_mono_accent()` instead.")
style_mono_accent(...)
}
#' @description
#' Use [style_mono_accent_inverse()] instead of `mono_accent_inverse()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
mono_accent_inverse <- function(...) {
.Deprecated(msg = "mono_accent_inverse() was renamed. Please use `style_mono_accent_inverse()` instead.")
style_mono_accent_inverse(...)
}
#' @description
#' Use [style_duo()] instead of `duo()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
duo <- function(...) {
.Deprecated(msg = "duo() was renamed. Please use `style_duo()` instead.")
style_duo(...)
}
#' @description
#' Use [style_duo_accent()] instead of `duo_accent()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
duo_accent <- function(...) {
.Deprecated(msg = "duo_accent() was renamed. Please use `style_duo_accent()` instead.")
style_duo_accent(...)
}
#' @description
#' Use [style_duo_accent_inverse()] instead of `duo_accent_inverse()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
duo_accent_inverse <- function(...) {
.Deprecated(msg = "duo_accent_inverse() was renamed. Please use `style_duo_accent_inverse()` instead.")
style_duo_accent_inverse(...)
}
#' @description
#' Use [style_solarized_light()] instead of `solarized_light()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
solarized_light <- function(...) {
.Deprecated(msg = "solarized_light() was renamed. Please use `style_solarized_light()` instead.")
style_solarized_light(...)
}
#' @description
#' Use [style_solarized_dark()] instead of `solarized_dark()`.
#'
#' @export
#' @keywords internal
#' @rdname xaringanthemer-deprecated
solarized_dark <- function(...) {
.Deprecated(msg = "solarized_dark() was renamed. Please use `style_solarized_dark()` instead.")
style_solarized_dark(...)
}
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/xaringanthemer-deprecated.R |
#' @importFrom grDevices col2rgb rgb rgb2hsv hsv
#' @keywords internal
"_PACKAGE"
xaringanthemer_env <- new.env(parent = emptyenv())
# I looked up these ggplot geom aesthetic defaults manually via e.g.
# ggplot2::geom_line()$geom$default_aes
xaringanthemer_env$std_ggplot_defaults <- list(
"line" = list(color = "black"),
"vline" = list(color = "black"),
"hline" = list(color = "black"),
"abline" = list(color = "black"),
"segment" = list(color = "black"),
"bar" = list(fill = "grey35"),
"col" = list(fill = "grey35"),
"boxplot" = list(color = "grey20", fill = "white"),
"contour" = list(color = "#3366FF"),
"density" = list(color = "black",
fill = NA,
alpha = NA),
"dotplot" = list(color = "black"),
"errorbarh" = list(color = "black"),
"crossbar" = list(color = "black"),
"errorbar" = list(color = "black"),
"linerange" = list(color = "black"),
"pointrange" = list(color = "black"),
"map" = list(color = "black"),
"path" = list(color = "black"),
"line" = list(color = "black"),
"step" = list(color = "black"),
"point" = list(color = "black"),
"polygon" = list(color = NA,
fill = "grey20"),
"quantile" = list(color = "#3366FF"),
"rug" = list(color = "black"),
"segment" = list(color = "black"),
"smooth" = list(fill = "grey60",
color = "#3366FF"),
"spoke" = list(color = "black"),
"label" = list(color = "black",
family = ""),
"text" = list(color = "black",
family = ""),
"rect" = list(fill = "grey35"),
"tile" = list(fill = "grey20"),
"violin" = list(fill = "white", color = "grey20")
)
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/xaringanthemer-package.R |
# nocov start
.onLoad <- function(libname, pkgname, ...) {
if ("knitr" %in% loadedNamespaces()) {
set_fig_showtext()
}
setHook(
packageEvent("knitr", "onLoad"),
function(...) {
set_fig_showtext()
}
)
invisible()
}
# nocov end
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/R/zzz.R |
## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
warning = FALSE,
comment = "#>",
fig.width = 6,
fig.height = 4
)
## ----setup, include=FALSE-----------------------------------------------------
library(xaringanthemer)
style_mono_accent(
base_color = "#DC322F",
inverse_background_color = "#002B36",
inverse_header_color = "#31b09e",
inverse_text_color = "#FFFFFF",
title_slide_background_color = "var(--base)",
text_font_google = google_font("Kelly Slab"),
header_font_google = google_font("Oleo Script"),
outfile = NULL
)
## ----ggplot2-demo-1, out.width = "48%", fig.show="hide"-----------------------
library(ggplot2)
g_base <- ggplot(mpg) +
aes(hwy, cty) +
geom_point() +
labs(x = "Highway MPG", y = "City MPG", title = "Fuel Efficiency")
# Basic plot with default theme
g_base
## ----ggplot2-demo-2, fig.show="hide"------------------------------------------
# Fancy slide-matching themed plot
g_base + theme_xaringan()
## ----eval=FALSE---------------------------------------------------------------
# theme_xaringan_restore_defaults()
## ----ggplot2-demo-inverse, fig.show="hide"------------------------------------
# theme_xaringan() on the left, theme_xaringan_inverse() on the right
g_base + theme_xaringan_inverse()
## ----eval=FALSE---------------------------------------------------------------
# theme_xaringan(css_file = "my-slide-style.css")
## ----eval=FALSE---------------------------------------------------------------
# theme_xaringan(
# text_color = "#3D3E38",
# background_color = "#FFFFFF",
# accent_color = "#DC322F",
# text_font = "Kelly Slab",
# text_font_use_google = TRUE,
# title_font = "Oleo Script",
# title_font_use_google = TRUE
# )
## ----demo-geom-defaults, fig.width = 10---------------------------------------
g_diamonds <- ggplot(diamonds, aes(x = cut)) +
geom_bar() +
labs(x = NULL, y = NULL, title = "Diamond Cut Quality") +
ylim(0, 25000)
g_diamonds + theme_xaringan()
## ----eval=FALSE---------------------------------------------------------------
# theme_xaringan_restore_defaults()
## ----scale-xaringan, fig.width = 9, fig.height = 5, out.width="48%", fig.show="hold", echo = TRUE----
ggplot(diamonds, aes(x = cut)) +
geom_bar(aes(fill = ..count..), show.legend = FALSE) +
labs(x = NULL, y = "Count", title = "Diamond Cut Quality") +
theme_xaringan() +
scale_xaringan_fill_continuous()
ggplot(mpg, aes(x = hwy, y = cty)) +
geom_count(aes(color = ..n..), show.legend = FALSE) +
labs(x = "Highway MPG", y = "City MPG", title = "Fuel Efficiency") +
theme_xaringan_inverse() +
scale_xaringan_color_continuous(breaks = seq(3, 12, 2), inverse = TRUE, begin = 1, end = 0)
## ----text demo, fig.width = 10------------------------------------------------
g_diamonds_with_text <-
g_diamonds +
geom_text(aes(y = ..count.., label = format(..count.., big.mark = ",")),
vjust = -0.30, size = 8, stat = "count") +
labs(x = "Cut", y = "Count")
g_diamonds_with_text + theme_xaringan()
## ----text-demo-2, fig.width = 10----------------------------------------------
g_diamonds_with_text +
theme_xaringan(
text_font = google_font("Ranga"),
title_font = google_font("Holtwood One SC")
)
## ----eval=FALSE---------------------------------------------------------------
# font_url <- file.path(
# "https://fontlibrary.org/assets/fonts/glacial-indifference/",
# "5f2cf277506e19ec77729122f27b1faf/0820b3c58fed35de298219f314635982",
# "GlacialIndifferenceRegular.ttf"
# )
#
# font_temp <- tempfile()
# download.file(font_url, font_temp)
## ----sysfonts-custom-font, fig.width = 10-------------------------------------
# Path to the local custom font file
font_temp <- system.file(
"fonts/GlacialIndifferenceRegular.ttf", package = "xaringanthemer"
)
# Register the font with sysfonts/showtext
sysfonts::font_add(family = "GlacialIndifferenceRegular", regular = font_temp)
# Now it's available for use!
g_diamonds_with_text +
theme_xaringan(
text_font = "GlacialIndifferenceRegular",
title_font = "GlacialIndifferenceRegular"
)
## ----eval=FALSE---------------------------------------------------------------
# ## On Windows
# # x11(width = 16 * 2/3, height = 9 * 2/3)
#
# ## On MacOS
# quartz(width = 16 * 2/3, height = 9 * 2/3)
# ## run plot code to preview in separate window
# dev.off() # call when done to close the device
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/inst/doc/ggplot2-themes.R |
---
title: "ggplot2 Themes"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{ggplot2 Themes}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
warning = FALSE,
comment = "#>",
fig.width = 6,
fig.height = 4
)
```
```{css echo=FALSE}
img { max-width: 100%; border: none; }
```
**xaringanthemer** provides two [ggplot2] themes for your [xaringan] slides
to help your data visualizations blend seamlessly into your slides.
Use `theme_xaringan()` to create plots that match your primary slide style
or `theme_xaringan_inverse()` to match the style of your inverse slides.
<img src="https://raw.githubusercontent.com/gadenbuie/xaringanthemer/assets/theme-xaringan-inverse.png" alt="Examples slides with ggplot2 plots that match the xaringanthemer theme" data-external="1" />
### Key Features
- The ggplot2 themes [uses the colors and themes](#setup-your-theme) from the **xaringanthemer** style functions, if you set your theme inside your slides. Otherwise, it [draws from the `xaringan-themer.css` file](#using-xaringan-themer-css).
- The themes [pick appropriate colors](#colors) for titles, grid lines, and axis text,
and also sets the default colors of geoms like `ggplot2::geom_point()` and
`ggplot2::geom_text()`. There are also monotone
[color and fill scales](#scale-xaringan) based around the primary accent color
used in your xaringan theme.
- If you use Google Fonts in your slides, the ggplot2 themes use the showtext
package to [automatically match the title and axis text fonts](#fonts)
of your plots to the heading and text fonts in your xaringan theme.
- I've done my best to set up everything so that _it just works_, but sometimes
the showtext package adds a bit of complication to the routine data
visualization workflow. At the end of this vignette I include
[a few tips](#tips) for working with showtext.
## Setup Your Theme
`theme_xaringan()` is designed to automatically use
the fonts and colors you used for your slides' style theme.
Here I'm going to use a moderately customized color theme
based on `style_mono_accent()`,
that results in the xaringan theme previewed in the slides above.
I've also picked out a few fonts from [Google Fonts][google-fonts]
that I would probably never use in a real presentation,
but they're flashy enough to make it easy to see
that we're not using the standard default fonts.
````markdown
```{r xaringan-themer, include=FALSE, warning=FALSE}`r ''`
library(xaringanthemer)
style_mono_accent(
base_color = "#DC322F", # bright red
inverse_background_color = "#002B36", # dark dark blue
inverse_header_color = "#31b09e", # light aqua green
inverse_text_color = "#FFFFFF", # white
title_slide_background_color = "var(--base)",
text_font_google = google_font("Kelly Slab"),
header_font_google = google_font("Oleo Script")
)
```
````
```{r setup, include=FALSE}
library(xaringanthemer)
style_mono_accent(
base_color = "#DC322F",
inverse_background_color = "#002B36",
inverse_header_color = "#31b09e",
inverse_text_color = "#FFFFFF",
title_slide_background_color = "var(--base)",
text_font_google = google_font("Kelly Slab"),
header_font_google = google_font("Oleo Script"),
outfile = NULL
)
```
If you use a hidden chunk like this one
inside your slides' R Markdown source file,
`theme_xaringan()` will know which colors and fonts you've picked.
Adding `theme_xaringan()` to a ggplot,
like this demonstration plot using the `mpg` dataset from ggplot2,
changes the colors and fonts of your plot theme.
```{r ggplot2-demo-1, out.width = "48%", fig.show="hide"}
library(ggplot2)
g_base <- ggplot(mpg) +
aes(hwy, cty) +
geom_point() +
labs(x = "Highway MPG", y = "City MPG", title = "Fuel Efficiency")
# Basic plot with default theme
g_base
```
```{r ggplot2-demo-2, fig.show="hide"}
# Fancy slide-matching themed plot
g_base + theme_xaringan()
```
<img src="`r knitr::fig_chunk("ggplot2-demo-1", "png")`" width="48%" /><img src="`r knitr::fig_chunk("ggplot2-demo-2", "png")`" width="48%" />
With `theme_xaringan()` the fonts and colors match the slide theme.
The default colors of points (like other geometries) has been changed as well
to match the slide colors.
To restore the previous default colors of ggplot2 geoms, call
```{r eval=FALSE}
theme_xaringan_restore_defaults()
```
Add `theme_xaringan_inverse()` to automatically create a plot
that matches the inverse slide style.
```{r ggplot2-demo-inverse, fig.show="hide"}
# theme_xaringan() on the left, theme_xaringan_inverse() on the right
g_base + theme_xaringan_inverse()
```
<img src="`r knitr::fig_chunk("ggplot2-demo-2", "png")`" width="48%" /><img src="`r knitr::fig_chunk("ggplot2-demo-inverse", "png")`" width="48%" />
## Using `theme_xaringan()` without calling a style function {#using-xaringan-themer-css}
Once you've set up your custom xaringan theme,
you might want to use the theme's CSS file for new presentations
instead of rebuilding your theme with every new slide deck.
In these cases, `theme_xaringan()` will look for a CSS file
written by **xaringanthemer** in your slides' directory
or in a sub-folder under the same directory
that it can use to determine the colors and fonts used in your slides.
If you happen to have multiple slide themes
written by **xaringanthemer** in the same directory,
the one named `xaringan-themer.css` will be used.
If xaringanthemer picks the wrong file,
you can use the `css_file` in `theme_xaringan()`
to specify exactly which CSS file to use.
```{r eval=FALSE}
theme_xaringan(css_file = "my-slide-style.css")
```
Note that you can use `theme_xaringan()` anywhere you want,
not just in xaringan slides!
(For example, `theme_xaringan()` is working great in these vignettes!)
This means that you can use your plot theme in reports and websites
while maintaining a consistent look and feel or brand.
Finally, you don't even need a xaringanthemer CSS file.
You can specify the key ingredients for the theme
as arguments to `theme_xaringan()`, namely
text, background, and accent colors as well as text and title fonts.
The R chunk below replicated the demonstrated theme,
but doesn't require a slide style to be set or stored in a CSS file.
```{r eval=FALSE}
theme_xaringan(
text_color = "#3D3E38",
background_color = "#FFFFFF",
accent_color = "#DC322F",
text_font = "Kelly Slab",
text_font_use_google = TRUE,
title_font = "Oleo Script",
title_font_use_google = TRUE
)
```
## Colors
As demonstrated above,
`theme_xaringan()` and `theme_xaringan_inverse()`
modify the default colors and fonts of geometries.
This means that `geom_point()`, `geom_bar()`, `geom_text()`
and other geoms used in your plots
will reasonably match your slide themes with no extra work.
```{r demo-geom-defaults, fig.width = 10}
g_diamonds <- ggplot(diamonds, aes(x = cut)) +
geom_bar() +
labs(x = NULL, y = NULL, title = "Diamond Cut Quality") +
ylim(0, 25000)
g_diamonds + theme_xaringan()
```
Whenever `theme_xaringan()` or `theme_xaringan_inverse()` are called,
the default values of many of ggplot2 geoms are set by default.
You can opt out of this by setting `set_ggplot_defaults = FALSE`
when using either theme.
You can also restore the geom aesthetic defaults to their original values
before the first time `theme_xaringan()` or `theme_xaringan_inverse()`
were used by running
```{r eval=FALSE}
theme_xaringan_restore_defaults()
```
### Custom Color and Fill Scales {#scale-xaringan}
xaringanthemer includes monotone color and fill scales
to match your ggplot2 theme.
The scale functions all follow the naming pattern
`scale_xaringan_<aes>_<data_type>()`,
where `<aes>` is replaced with either `color` or `fill`
and `<data_type>` is one of `discrete` or `continuous`.
These scales use `colorspace::sequential_hcl()`
to create a sequential, monotone color scale
based on the primary accent color in your slides.
Color scales matching the inverse slides are possible
by setting the argument `inverse = TRUE`.
```{r scale-xaringan, fig.width = 9, fig.height = 5, out.width="48%", fig.show="hold", echo = TRUE}
ggplot(diamonds, aes(x = cut)) +
geom_bar(aes(fill = ..count..), show.legend = FALSE) +
labs(x = NULL, y = "Count", title = "Diamond Cut Quality") +
theme_xaringan() +
scale_xaringan_fill_continuous()
ggplot(mpg, aes(x = hwy, y = cty)) +
geom_count(aes(color = ..n..), show.legend = FALSE) +
labs(x = "Highway MPG", y = "City MPG", title = "Fuel Efficiency") +
theme_xaringan_inverse() +
scale_xaringan_color_continuous(breaks = seq(3, 12, 2), inverse = TRUE, begin = 1, end = 0)
```
In general, these color scales aren't great
at representing the underlying data.
In both examples above,
the color and fill scales duplicate information displayed via other aesthetics
(the height of the bar or the size of the point).
I recommend using these scales primarily for style,
although the scales can be more or less effective
depending on your color scheme.
The scales come with a few more options:
- Choose a different primary color using the `color` argument.
- Use the inverse color slide theme color with `inverse = TRUE`
(only applies when `color` is not supplied).
- Invert the direction of the discrete scales with `direction = -1`.
- Control the range of the continuous color scale used with `begin` and `end`.
You can also invert the direction of the continuous color scale by setting
`begin = 1` and `end = 0`.
## Fonts
### Automatically match slide and plot fonts
xaringanthemer uses the [showtext] and [sysfonts] packages by Yixuan Qiu
to automatically download and register [Google Fonts][google-fonts]
for use with your ggplot2 plots.
In your slide theme,
use the `<type>_font_google` argument
with the `google_font("<font name>")` helper
(or the default xaringanthemer fonts)
and `theme_xaringan()` will handle the rest.
In our demo theme, we used `style_mono_accent()` with
- `text_font_google = google_font("Kelley Slab")` and
- `header_font_google = google_font("Oleo Script")`.
```{r text demo, fig.width = 10}
g_diamonds_with_text <-
g_diamonds +
geom_text(aes(y = ..count.., label = format(..count.., big.mark = ",")),
vjust = -0.30, size = 8, stat = "count") +
labs(x = "Cut", y = "Count")
g_diamonds_with_text + theme_xaringan()
```
`theme_xaringan()` applies the header font to the plot and axis titles
and the text font to the axis ticks labels and any text geoms or annotations.
### Manually specify plot fonts
You can also specify specific fonts for your plot theme.
Both `text_font` and `title_font` in `theme_xaringan()` and `theme_xaringan_inverse()`
accept `google_font()`s directly.
```{r text-demo-2, fig.width = 10}
g_diamonds_with_text +
theme_xaringan(
text_font = google_font("Ranga"),
title_font = google_font("Holtwood One SC")
)
```
### Using fonts not in Google Fonts
If you want to use a font that isn't in the Google Fonts collection,
you need to manually register the font with sysfonts
so that it can be used in your plots.
I found a nice open source font called
[Glacial Indifference](https://fontlibrary.org/en/font/glacial-indifference)
by Alfredo Marco Pradil
available at [fontlibrary.org](https://fontlibrary.org).
In my theme style function,
I would use
```
style_mono_accent(
text_font_family = "GlacialIndifferenceRegular",
text_font_url = "https://fontlibrary.org/face/glacial-indifference"
)
```
but sysfonts won't know where to find the TTF font files for this font.
To register the font with sysfonts, we use `sysfonts::font_add()`,
but first we need to download the font file —
the `sysfonts::font_add()` function requires the font file to be local.
By inspecting the CSS file at the link I used in `text_font_url`,
I found a direct URL for the `.ttf` files for _GlacialIndifferenceRegular_.
I've included the code I used to download the font to a temporary file below,
but in case the URL breaks, I've included _Glacial Indifference_
in the xaringanthemer package.
```{r eval=FALSE}
font_url <- file.path(
"https://fontlibrary.org/assets/fonts/glacial-indifference/",
"5f2cf277506e19ec77729122f27b1faf/0820b3c58fed35de298219f314635982",
"GlacialIndifferenceRegular.ttf"
)
font_temp <- tempfile()
download.file(font_url, font_temp)
```
```{r sysfonts-custom-font, fig.width = 10}
# Path to the local custom font file
font_temp <- system.file(
"fonts/GlacialIndifferenceRegular.ttf", package = "xaringanthemer"
)
# Register the font with sysfonts/showtext
sysfonts::font_add(family = "GlacialIndifferenceRegular", regular = font_temp)
# Now it's available for use!
g_diamonds_with_text +
theme_xaringan(
text_font = "GlacialIndifferenceRegular",
title_font = "GlacialIndifferenceRegular"
)
```
## Tips for using the showtext package {#tips}
Working with fonts is notoriously frustrating,
but [showtext] and [sysfonts] do a great job ensuring that
Google Fonts and custom fonts work on all platforms.
As you've seen in the examples above,
the process is mostly seamless,
but there are a few caveats and
places where the methods used by these packages may interrupt a typical ggplot2 workflow.
### R Markdown
To use the showtext package in R Markdown,
knitr requires that the `fig.showtext` chunk option be set to `TRUE`,
either in the chunk producing the figure or globally in the document.
xaringanthemer tries to set this chunk option for you,
but in some circumstances it's possible to call `theme_xaringan()`
in a way that xaringanthemer can't set this option for you.
When this happens,
xaringanthemer will produce an error:
```
Error in verify_fig_showtext(fn) :
To use theme_xaringan_base() with knitr, you need to set the chunk
option `fig.showtext = TRUE` for this chunk. Or you can set this option
globally with `knitr::opts_chunk$set(fig.showtext = TRUE)`.
```
If you find yourself facing this error,
follow the instructions and choose one of the two suggestions:
1. Add `fig.showtext = TRUE` to the chunk producing the figure
2. Or set the option globally in your `setup` chunk with
`knitr::opts_chunk$set(fig.showtext = TRUE)`.
### MacOS
On MacOS, you'll need to have `xquartz` installed for `sysfonts` to work properly.
If you use [homebrew](https://brew.sh/),
you can install `xquartz` with
```bash
brew cask install xquartz
```
### In RStudio
showtext and RStudio's graphic device don't always work well together.
Depending on your version of RStudio,
if you try to preview plots that use `theme_xaringan()`,
the fonts in the preview will still be the default sans font
or you may not see a plot at all.
To work around this, open a new `quartz()` (MacOS) or `x11()` (Windows/Unix) plot device.
The plots will then render in a separate window.
I usually create a `quartz()` device with a similar size ratio to my slides.
```{r eval=FALSE}
## On Windows
# x11(width = 16 * 2/3, height = 9 * 2/3)
## On MacOS
quartz(width = 16 * 2/3, height = 9 * 2/3)
## run plot code to preview in separate window
dev.off() # call when done to close the device
```
[ggplot2]: https://ggplot2.tidyverse.org
[xaringan]: https://github.com/yihui/xaringan
[google-fonts]: https://fonts.google.com
[showtext]: https://github.com/yixuan/showtext
[sysfonts]: https://github.com/yixuan/sysfonts
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/inst/doc/ggplot2-themes.Rmd |
## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
## ----table, results = "asis", echo=FALSE--------------------------------------
tv <- xaringanthemer:::template_variables
tv$variable <- glue::glue_data(tv, "`{variable}`")
tv[!is.na(tv$css_variable), "css_variable"] <- glue::glue("`{tv$css_variable[!is.na(tv$css_variable)]}`")
tv[is.na(tv$css_variable), "css_variable"] <- ""
tv[is.na(tv$css_property), "css_property"] <- ""
tv$default <- gsub("[{}]", "", tv$default)
tv <- tv[, c(
"variable", "description", "element", "css_property", "default", "css_variable"
)]
knitr::kable(
tv,
col.names = c("Variable", "Description", "Element", "CSS Property", "Default", "CSS Variable")
)
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/inst/doc/template-variables.R |
---
title: "Template Variables"
output:
rmarkdown::html_vignette: default
vignette: >
%\VignetteIndexEntry{Template Variables}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
The following table shows the template variables,
their default values in the standard `xaringanthemer` theme,
the primary element to which the property is applied,
and a brief description of the template variable.
For example, `background_color` by default sets the `background-color` CSS property of the `.remark-slide-content` class to `#FFF`.
Use this table to find the template variable you would like to modify.
You can also use this table to find the CSS class or element associated with a particular template item.
Note that some theme functions,
like `style_mono_accent()`,
have additional parameters
and a specific set of default values unique to the theme.
However, with any theme function
you can override the theme's defaults
by directly setting any of the arguments listed below
when calling the theme function.
To be concrete,
`style_mono_accent()` has three additional arguments:
`base_color` (the accent color), `white_color`, and `black_color`.
In this theme,
the background slide color defaults to `white_color`,
but you can choose a different slide background color
by setting `background_color`,
for example `background_color = "#EAEAEA"`.
```{r table, results = "asis", echo=FALSE}
tv <- xaringanthemer:::template_variables
tv$variable <- glue::glue_data(tv, "`{variable}`")
tv[!is.na(tv$css_variable), "css_variable"] <- glue::glue("`{tv$css_variable[!is.na(tv$css_variable)]}`")
tv[is.na(tv$css_variable), "css_variable"] <- ""
tv[is.na(tv$css_property), "css_property"] <- ""
tv$default <- gsub("[{}]", "", tv$default)
tv <- tv[, c(
"variable", "description", "element", "css_property", "default", "css_variable"
)]
knitr::kable(
tv,
col.names = c("Variable", "Description", "Element", "CSS Property", "Default", "CSS Variable")
)
```
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/inst/doc/template-variables.Rmd |
## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
results = "asis",
echo = FALSE,
comment = "#>",
out.width = "100%"
)
library(xaringanthemer)
## ----include=FALSE------------------------------------------------------------
IN_PKGDOWN <- identical(Sys.getenv("IN_PKGDOWN"), "true")
## ----xaringanthemer-ggplot-setup, include=FALSE, eval=!IN_PKGDOWN-------------
style_mono_accent(
base_color = "#1c5253",
header_font_google = google_font("Josefin Sans"),
text_font_google = google_font("Montserrat", "300", "300i"),
code_font_google = google_font("Fira Mono"),
outfile = NULL
)
## ----theme_xaringan_demo, echo=TRUE, warning=FALSE, fig.width=13, fig.height=5.5, eval=!IN_PKGDOWN, fig.showtext=TRUE----
library(ggplot2)
ggplot(diamonds) +
aes(cut, fill = cut) +
geom_bar(show.legend = FALSE) +
labs(
x = "Cut",
y = "Count",
title = "A Fancy diamonds Plot"
) +
theme_xaringan(background_color = "#FFFFFF") +
scale_xaringan_fill_discrete()
## ----link-to-plot-image, echo=FALSE, eval=IN_PKGDOWN, results='asis'----------
# cat("")
## ----include=FALSE------------------------------------------------------------
IS_README <- exists("IS_README") && IS_README
include_graphic <- function(img_path) {
glue::glue(
'<img src="https://raw.githubusercontent.com/gadenbuie/',
'xaringanthemer/assets/{img_path}" data-external="1" />'
)
}
## ----style_mono_light---------------------------------------------------------
demo_function_call <- function(f, n_params = 1) {
cat(sep = "",
"```r\n",
paste(substitute(f)), "(",
if (n_params > 0) paste(collapse = ", ",
sapply(1:n_params, function(i) {
paste0(names(formals(f))[i], ' = "', formals(f)[[i]], '"')})),
")\n```"
)
}
demo_function_call(style_mono_light, 1)
## ----style_mono_dark----------------------------------------------------------
demo_function_call(style_mono_dark, 1)
## ----style_mono_accent--------------------------------------------------------
demo_function_call(style_mono_accent, 1)
## ----style_mono_accent_inverse------------------------------------------------
demo_function_call(style_mono_accent_inverse, 1)
## ----style_duo----------------------------------------------------------------
demo_function_call(style_duo, 2)
## ----style_duo_accent---------------------------------------------------------
demo_function_call(style_duo_accent, 2)
## ----style_duo_accent_inverse-------------------------------------------------
demo_function_call(style_duo_accent_inverse, 2)
## ----style_solarized_light----------------------------------------------------
demo_function_call(style_solarized_light, 0)
## ----style_solarized_dark-----------------------------------------------------
demo_function_call(style_solarized_dark, 0)
## ---- results='asis', echo=FALSE----------------------------------------------
tvv <- xaringanthemer:::template_variables$variable
cat(paste0("- `", tvv[grepl("^text_", tvv)][1:5], "`"), sep = "\n")
cat("- *and more ...*")
## ----results='asis', echo=FALSE-----------------------------------------------
cat(paste0("- `", tvv[grepl("^title_slide_", tvv)], "`"), sep = "\n")
## ----eval=FALSE, echo=TRUE----------------------------------------------------
# style_xaringan(
# text_font_family = "Droid Serif",
# text_font_url = "https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic",
# header_font_google = google_font("Yanone Kaffeesatz")
# )
## ----results='asis', echo=FALSE-----------------------------------------------
cat(paste0("`", tvv[grepl("_font_google$", tvv)], "`", collapse = ", "))
## ----eval=FALSE, echo=TRUE----------------------------------------------------
# style_mono_light(
# header_font_google = google_font("Josefin Slab", "600"),
# text_font_google = google_font("Work Sans", "300", "300i"),
# code_font_google = google_font("IBM Plex Mono")
# )
## ----eval=FALSE, echo=TRUE----------------------------------------------------
# style_solarized_dark(
# code_font_family = "Fira Code",
# code_font_url = "https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/fira_code.css"
# )
## ----eval=FALSE, echo=TRUE----------------------------------------------------
# style_mono_light(
# extra_fonts = list(
# google_font("Sofia"),
# # Young Serif by uplaod.fr
# "https://cdn.jsdelivr.net/gh/uplaod/YoungSerif/fonts/webfonts/fontface.css",
# ),
# extra_css = list(
# ".title-slide h2" = list("font-family" = "Sofia"),
# blockquote = list("font-family" = "youngserifregular")
# )
# )
## ----results='asis', echo=FALSE-----------------------------------------------
extra_css <- list(
".small" = list("font-size" = "90%"),
".full-width" = list(
display = "flex",
width = "100%",
flex = "1 1 auto"
)
)
cat(
"\n```css",
"/* Extra CSS */",
xaringanthemer:::list2css(extra_css),
"```",
sep = "\n"
)
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/inst/doc/xaringanthemer.R |
---
title: "Xaringan CSS Theme Generator"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Overview of xaringanthemer}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
results = "asis",
echo = FALSE,
comment = "#>",
out.width = "100%"
)
library(xaringanthemer)
```
```{css echo=FALSE}
img { max-width: 100%; }
```
[xaringan]: https://github.com/yihui/xaringan
[remarkjs]: https://github.com/gnab/remark
Jump to:
[Quick Intro](#quick-intro),
[Themes](#themes),
[Theme Settings](#theme-settings),
[Fonts](#fonts),
[Colors](#colors),
[Adding Custom CSS](#adding-custom-css)
## Quick Intro
[theme-functions]: #themes
[theme-settings]: #theme-settings
[template-variables]: template-variables.html
```{r child="../man/fragments/_quick-intro.Rmd"}
```
## Themes
```{r child="../man/fragments/_themes.Rmd"}
```
## Theme Settings
The theme functions listed above are just wrappers around the central function of this package, `style_xaringan()`.
If you want to start from the default **xaringan** theme and make a few modifications, start there.
All of the theme template variables are repeated in each of the theme functions (instead of relying on `...`) so that you can use autocompletion to find and change the defaults for any theme function.
To override the default value of any theme functions, set the appropriate argument in the theme function.
A table of all template variables is included in [`vignette("template-variables", "xaringanthemer")`](template-variables.html).
As an example, try loading `xaringanthemer`, type out `style_duo_theme(` and then press <kbd>Tab</kbd> to see all of the theme options.
All of the theme options are named so that you first think of the element you want to change, then the property of that element.
Here are some of the `text_` theme options:
```{r, results='asis', echo=FALSE}
tvv <- xaringanthemer:::template_variables$variable
cat(paste0("- `", tvv[grepl("^text_", tvv)][1:5], "`"), sep = "\n")
cat("- *and more ...*")
```
And here are the title slide theme options:
```{r results='asis', echo=FALSE}
cat(paste0("- `", tvv[grepl("^title_slide_", tvv)], "`"), sep = "\n")
```
## Fonts
[adding-custom-css]: #adding-custom-css
```{r child="../man/fragments/_fonts.Rmd"}
```
## Colors
```{r child="../man/fragments/_colors.Rmd"}
```
## Adding Custom CSS
You can also add custom CSS classes using the `extra_css` argument in the theme functions.
This argument takes a named list of CSS definitions each containing a named list of CSS property-value pairs.
```r
extra_css <- list(
".small" = list("font-size" = "90%"),
".full-width" = list(
display = "flex",
width = "100%",
flex = "1 1 auto"
)
)
```
If you would rather keep your additional css definitions in a separate file, you can call `style_extra_css()` separately.
Just be sure to include your new CSS file in the list of applied files in your YAML header.
```r
style_extra_css(css = extra_css, outfile = "custom.css")
```
```{r results='asis', echo=FALSE}
extra_css <- list(
".small" = list("font-size" = "90%"),
".full-width" = list(
display = "flex",
width = "100%",
flex = "1 1 auto"
)
)
cat(
"\n```css",
"/* Extra CSS */",
xaringanthemer:::list2css(extra_css),
"```",
sep = "\n"
)
```
This is most helpful when wanting to define helper classes to work with the [remark.js][remarkjs] `.class[]` syntax.
Using the above example, we could add slide text `.small[in smaller font size]`.
```{r child="../man/fragments/_thanks.Rmd"}
```
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/inst/doc/xaringanthemer.Rmd |
---
title: "Presentation Ninja"
subtitle: "⚔️ xaringan +<br/>😎 xaringanthemer"
author:
- "Yihui Xie"
- "Garrick Aden-Buie"
date: '`r Sys.Date()`'
output:
xaringan::moon_reader:
css: xaringan-themer.css
nature:
slideNumberFormat: "%current%"
highlightStyle: github
highlightLines: true
ratio: 16:9
countIncrementalSlides: true
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
knitr::opts_chunk$set(
fig.width=9, fig.height=3.5, fig.retina=3,
out.width = "100%",
cache = FALSE,
echo = TRUE,
message = FALSE,
warning = FALSE,
hiline = TRUE
)
```
```{r xaringan-themer, include=FALSE, warning=FALSE}
library(xaringanthemer)
style_duo_accent(
primary_color = "#1381B0",
secondary_color = "#FF961C",
inverse_header_color = "#FFFFFF"
)
```
## Typography
Text can be **bold**, _italic_, ~~strikethrough~~, or `inline code`.
[Link to another slide](#colors).
### Lorem Ipsum
Dolor imperdiet nostra sapien scelerisque praesent curae metus facilisis dignissim tortor.
Lacinia neque mollis nascetur neque urna velit bibendum.
Himenaeos suspendisse leo varius mus risus sagittis aliquet venenatis duis nec.
- Dolor cubilia nostra nunc sodales
- Consectetur aliquet mauris blandit
- Ipsum dis nec porttitor urna sed
---
name: colors
## Colors
.left-column[
Text color
[Link Color](#3)
**Bold Color**
_Italic Color_
`Inline Code`
]
.right-column[
Lorem ipsum dolor sit amet, [consectetur adipiscing elit (link)](#3),
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Erat nam at lectus urna.
Pellentesque elit ullamcorper **dignissim cras tincidunt (bold)** lobortis feugiat.
_Eros donec ac odio tempor_ orci dapibus ultrices.
Id porta nibh venenatis cras sed felis eget velit aliquet.
Aliquam id diam maecenas ultricies mi.
Enim sit amet
`code_color("inline")`
venenatis urna cursus eget nunc scelerisque viverra.
]
---
# Big Topic or Inverse Slides `#`
## Slide Headings `##`
### Sub-slide Headings `###`
#### Bold Call-Out `####`
This is a normal paragraph text. Only use header levels 1-4.
##### Possible, but not recommended `#####`
###### Definitely don't use h6 `######`
---
# Left-Column Headings
.left-column[
## First
## Second
## Third
]
.right-column[
Dolor quis aptent mus a dictum ultricies egestas.
Amet egestas neque tempor fermentum proin massa!
Dolor elementum fermentum pharetra lectus arcu pulvinar.
]
---
class: inverse center middle
# Topic Changing Interstitial
--
```
class: inverse center middle
```
---
layout: true
## Blocks
---
### Blockquote
> This is a blockquote following a header.
>
> When something is important enough, you do it even if the odds are not in your favor.
---
### Code Blocks
#### R Code
```{r eval=FALSE}
ggplot(gapminder) +
aes(x = gdpPercap, y = lifeExp, size = pop, color = country) +
geom_point() +
facet_wrap(~year)
```
#### JavaScript
```js
var fun = function lang(l) {
dateformat.i18n = require('./lang/' + l)
return true;
}
```
---
### More R Code
```{r eval=FALSE}
dplyr::starwars %>% dplyr::slice_sample(n = 4)
```
---
```{r message=TRUE, eval=requireNamespace("cli", quietly = TRUE)}
cli::cli_alert_success("It worked!")
```
--
```{r message=TRUE}
message("Just a friendly message")
```
--
```{r warning=TRUE}
warning("This could be bad...")
```
--
```{r error=TRUE}
stop("I hope you're sitting down for this")
```
---
layout: true
## Tables
---
exclude: `r if (requireNamespace("tibble", quietly=TRUE)) "false" else "true"`
```{r eval=requireNamespace("tibble", quietly=TRUE)}
tibble::as_tibble(mtcars)
```
---
```{r}
knitr::kable(head(mtcars), format = 'html')
```
---
exclude: `r if (requireNamespace("DT", quietly=TRUE)) "false" else "true"`
```{r eval=requireNamespace("DT", quietly=TRUE)}
DT::datatable(head(mtcars), fillContainer = FALSE, options = list(pageLength = 4))
```
---
layout: true
## Lists
---
.pull-left[
#### Here is an unordered list:
* Item foo
* Item bar
* Item baz
* Item zip
]
.pull-right[
#### And an ordered list:
1. Item one
1. Item two
1. Item three
1. Item four
]
---
### And a nested list:
- level 1 item
- level 2 item
- level 2 item
- level 3 item
- level 3 item
- level 1 item
- level 2 item
- level 2 item
- level 2 item
- level 1 item
- level 2 item
- level 2 item
- level 1 item
---
### Nesting an ol in ul in an ol
- level 1 item (ul)
1. level 2 item (ol)
1. level 2 item (ol)
- level 3 item (ul)
- level 3 item (ul)
- level 1 item (ul)
1. level 2 item (ol)
1. level 2 item (ol)
- level 3 item (ul)
- level 3 item (ul)
1. level 4 item (ol)
1. level 4 item (ol)
- level 3 item (ul)
- level 3 item (ul)
- level 1 item (ul)
---
layout: true
## Plots
---
```{r plot-example, eval=requireNamespace("ggplot2", quietly=TRUE)}
library(ggplot2)
(g <- ggplot(mpg) + aes(hwy, cty, color = class) + geom_point())
```
---
```{r plot-example-themed, eval=requireNamespace("showtext", quietly=TRUE) && requireNamespace("ggplot2", quietly=TRUE)}
g + xaringanthemer::theme_xaringan(text_font_size = 16, title_font_size = 18) +
ggtitle("A Plot About Cars")
```
.footnote[Requires `{showtext}`]
---
layout: false
## Square image
<center><img src="https://octodex.github.com/images/labtocat.png" alt="GithHub Octocat" height="400px" /></center>
.footnote[GitHub Octocat]
---
### Wide image

.footnote[Wide images scale to 100% slide width]
---
## Two images
.pull-left[

]
.pull-right[

]
---
### Definition lists can be used with HTML syntax.
<dl>
<dt>Name</dt>
<dd>Godzilla</dd>
<dt>Born</dt>
<dd>1952</dd>
<dt>Birthplace</dt>
<dd>Japan</dd>
<dt>Color</dt>
<dd>Green</dd>
</dl>
---
class: center, middle
# Thanks!
Slides created via the R packages:
[**xaringan**](https://github.com/yihui/xaringan)<br>
[gadenbuie/xaringanthemer](https://github.com/gadenbuie/xaringanthemer)
The chakra comes from [remark.js](https://remarkjs.com), [**knitr**](http://yihui.name/knitr), and [R Markdown](https://rmarkdown.rstudio.com).
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/inst/rmarkdown/templates/xaringanthemer/skeleton/skeleton.Rmd |
source(here::here("R/utils_theme-gen.R"))
load(here::here("R/sysdata.rda"))
# R/theme_settings.R contains element_description() and plural_elements()
setup_theme_function <- function(
f_name = "style_xaringan",
template = template_variables,
...,
file = "",
body = " eval(parse(text = call_style_xaringan()))",
theme_colors = NULL
) {
if (file == "clip" && !requireNamespace("clipr", quietly = TRUE)) file <- ""
f_body_theme_colors <- include_theme_colors(theme_colors)
f_body <- c(
" # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R",
f_body_theme_colors,
body
)
tv <- template
f_def <- c(
"# Generated by inst/scripts/generate_theme_functions.R: do not edit by hand\n",
as.character(
glue::glue_data(
tv,
"#' @param {variable} {description}. ",
"Defaults to {gsub('[{{}}]', '`', default)}. ",
"{element_description(element)}",
"{describe_css_property(css_property)}",
"{describe_css_variable(css_variable)}"
)
),
"#' @template theme_params",
"#' @template style-usage",
...,
glue::glue("{f_name} <- function("),
as.character(
glue::glue_data(
tv,
" {variable} = {ifelse(!grepl('^[{].+[}]$', default), paste0('\"', default, '\"'), gsub('[{}]', '', default))},"
)
),
" colors = NULL,",
" extra_css = NULL,",
" extra_fonts = NULL,",
" outfile = \"xaringan-themer.css\"",
") {"
)
if (!is.null(f_body)) f_def <- c(f_def, f_body, "}")
if (file == "clip") {
clipr::write_clip(f_def)
message("Wrote ", f_name, " function signature to clipboard.")
} else {
cat(reflow_roxygen(f_def), sep = "\n", file = file)
message("Wrote ", f_name, " to ", file)
}
invisible()
}
reflow_roxygen <- function(x) {
is_roxy_tag <- grepl("^#' @", x)
roxy_tags <- x[is_roxy_tag]
roxy_tags <- sub("^#' ", "", roxy_tags)
roxy_tags <- purrr::map_chr(
roxy_tags,
~ paste(
"#'", strwrap(
pack_inline_code(.x),
width = 77,
exdent = 2
), collapse = "\n")
)
roxy_tags <- gsub("\u00A0", " ", roxy_tags)
x[is_roxy_tag] <- roxy_tags
x
}
pack_inline_code <- function(x) {
stopifnot(length(x) == 1, is.character(x))
x <- strsplit(x, "")[[1]]
inline_code <- FALSE
for (i in seq_along(x)) {
if (identical(x[i], "`")) {
inline_code <- !inline_code
} else if (inline_code && identical(x[i], " ")) {
x[i] <- "\u00A0"
}
}
paste(x, collapse = "")
}
include_theme_colors <- function(theme_colors = NULL) {
if (is.null(theme_colors)) return(NULL)
unname <- glue::glue("{theme_colors} <- unname({theme_colors})")
unname <- paste(unname, collapse = "\n ")
x <- glue::glue('{names(theme_colors)} = {theme_colors}')
x <- paste(x, collapse = ", ")
glue::glue(" {unname}\n colors <- c({x}, colors)", .trim = FALSE)
}
# ---- Write Xaringan Theme Function ----
setup_theme_function(
"style_xaringan",
template_variables,
"#' @template style_xaringan",
"#' @export",
body = paste0(" ", readLines(here::here("inst/scripts/style_xaringan_body.R"))),
file = here::here("R/style_xaringan.R")
)
# ---- Monotone Light ----
setup_theme_function(
"style_mono_light",
template_mono_light,
"#' @template style_mono_light",
"#' @family Monotone themes",
"#' @export",
file = here::here("R/style_mono_light.R"),
theme_colors = c(base = "base_color", white = "white_color", black = "black_color")
)
# ---- Monotone Dark ----
setup_theme_function(
"style_mono_dark",
template_mono_dark,
"#' @template style_mono_dark",
"#' @family Monotone themes",
"#' @export",
file = here::here("R/style_mono_dark.R"),
theme_colors = c(base = "base_color", white = "white_color", black = "black_color")
)
# ---- Monotone Accent ----
setup_theme_function(
"style_mono_accent",
template_mono_accent,
"#' @template style_mono_accent",
"#' @family Monotone themes",
"#' @export",
file = here::here("R/style_mono_accent.R"),
theme_colors = c(base = "base_color", white = "white_color", black = "black_color")
)
# ---- Monotone Accent Inverse ----
setup_theme_function(
"style_mono_accent_inverse",
template_mono_accent_inverse,
"#' @template style_mono_accent_inverse",
"#' @family Monotone themes",
"#' @export",
file = here::here("R/style_mono_accent_inverse.R"),
theme_colors = c(base = "base_color", white = "white_color", black = "black_color")
)
# ---- Duotone ----
setup_theme_function(
"style_duo",
template_duo,
"#' @template style_duo",
"#' @family Duotone themes",
"#' @export",
file = here::here("R/style_duo.R"),
theme_colors = c(primary = "primary_color", secondary = "secondary_color")
)
# ---- Duotone Accent ----
setup_theme_function(
"style_duo_accent",
template_duo_accent,
"#' @template style_duo_accent",
"#' @family Duotone themes",
"#' @export",
file = here::here("R/style_duo_accent.R"),
theme_colors = c(primary = "primary_color", secondary = "secondary_color",
white = "white_color", black = "black_color")
)
# ---- Duotone Accent Inverse ----
setup_theme_function(
"style_duo_accent_inverse",
template_duo_accent_inverse,
"#' @template style_duo_accent_inverse",
"#' @family Duotone themes",
"#' @export",
file = here::here("R/style_duo_accent_inverse.R"),
theme_colors = c(primary = "primary_color", secondary = "secondary_color",
white = "white_color", black = "black_color")
)
# ---- Solarized Light ----
setup_theme_function(
"style_solarized_light",
template_solarized_light,
"#' @template style_solarized_light",
"#' @family Solarized themes",
"#' @export",
file = here::here("R/style_solarized_light.R")
)
# ---- Solarized Dark ----
setup_theme_function(
"style_solarized_dark",
template_solarized_dark,
"#' @template style_solarized_dark",
"#' @family Solarized themes",
"#' @export",
file = here::here("R/style_solarized_dark.R")
)
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/inst/scripts/generate_theme_functions.R |
force(text_font_family)
force(text_font_weight)
force(text_font_url)
force(text_font_family_fallback)
force(header_font_family)
force(header_font_weight)
force(header_font_url)
force(code_font_family)
force(code_font_url)
force(code_font_family_fallback)
# the defaults are google fonts
is_default <- function(type, suffix) {
# check if font arg value is from xaringanthemer_font_default
var <- paste0(type, "_", suffix)
inherits(
get(var, envir = parent.frame(2), inherits = FALSE),
"xaringanthemer_default"
)
}
for (var in c("text", "header", "code")) {
suffixes <- c("font_family", "font_weight", "font_url")
if (var == "code") suffixes <- setdiff(suffixes, "font_weight")
var_is_google <- all(vapply(suffixes, is_default, logical(1), type = var))
var_is_google <- as.integer(var_is_google)
r_set_font_is_google <- glue::glue("{var}_font_is_google <- {var_is_google}")
eval(parse(text = r_set_font_is_google))
}
# Make sure font names are wrapped in quotes if they have spaces
f_args <- names(formals(sys.function()))
for (var in f_args[grepl("font_family$", f_args)]) {
var_value <- get(var, inherits = FALSE)
if (!is.null(var_value)) {
eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")")))
}
}
# Warn if base_font_size isn't absolute
css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px")
if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) {
warning(
glue::glue(
"Base font size '{base_font_size}' is not in absolute units. ",
"For best results, specify the `base_font_size` using absolute CSS units: ",
"{paste(css_abs_units, collapse = ', ')}"
),
call. = FALSE,
immediate. = TRUE
)
}
# If certain colors aren't in hexadecimal it may cause problems with theme_xaringan()
# TODO: at some point I'd rather be able to process CSS colors or variables
colors_used_by_theme_xaringan <- list(
background_color = background_color,
text_color = text_color,
header_color = header_color,
text_bold_color = text_bold_color,
inverse_background_color = inverse_background_color,
inverse_text_color = inverse_text_color,
inverse_header_color = inverse_header_color
)
colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null)
colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL)
if (any(!colors_are_hex)) {
colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex]
colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ")
warning(
glue::glue("Colors that will be used by `theme_xaringan()` need to be in ",
"hexadecimal format: {colors_better_as_hex}"),
immediate. = TRUE,
call. = FALSE
)
}
# Use font_..._google args to overwrite font args
for (var in f_args[grepl("font_google$", f_args)]) {
gf <- eval(parse(text = var))
if (is.null(gf)) next
if (!inherits(gf, "google_font")) {
stop("`", var, "` must be set using `google_font()`.")
}
group <- strsplit(var, "_")[[1]][1]
if (group == "text") {
text_font_family <- quote_elements_w_spaces(gf$family)
text_font_weight <- gf$weights %||% "normal"
if (grepl(",", text_font_weight)) {
# Use first font weight if multiple are imported
text_font_weight <- substr(text_font_weight, 1, regexpr(",", text_font_weight)[1] - 1)
}
text_font_url <- gf$url
} else {
eval(parse(text = paste0(group, "_font_family <- quote_elements_w_spaces(gf$family)")))
eval(parse(text = paste0(group, "_font_url <- gf$url")))
}
eval(parse(text = paste0(group, "_font_is_google <- 1")))
}
extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts)
extra_font_imports <- paste(extra_font_imports, collapse = "\n")
# convert NA arguments to NULL
for (var in f_args) {
val <- eval(parse(text = var))
if (is.null(val)) next
val <- val[!is.na(val)]
is_na <- length(val) == 0
if (is_na) assign(var, NULL, envir = sys.frame(sys.nframe()))
}
# prepare variables for template
body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ")
background_size_fallback <- if (is.null(background_position)) "cover" else "100%"
background_size <- background_image %??% (background_size %||% background_size_fallback)
title_slide_background_size <- title_slide_background_size %||% (
title_slide_background_image %??% "cover"
)
table_row_even_background_color <- table_row_even_background_color %||% background_color
# stash theme settings in package env
lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env))
for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) {
assign(
font_is_google,
get(font_is_google, inherits = FALSE) == 1,
envir = xaringanthemer_env
)
}
xaringanthemer_version <- utils::packageVersion("xaringanthemer")
# prepare header background object
needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes)
header_background_ignore_classes[needs_leading_dot] <- paste0(
".",
header_background_ignore_classes[needs_leading_dot]
)
header_background_ignore_classes <- purrr::map(
header_background_ignore_classes,
~ list(class = .)
)
if (is.null(header_background_padding)) {
slide_padding <- css_get_padding(padding)
header_background_padding <- paste(
"2rem", slide_padding$right, "1.5rem", slide_padding$left
)
}
header_background <- list(
auto = header_background_auto,
background_color = header_background_color,
text_color = header_background_text_color,
padding = header_background_padding,
content_padding_top = header_background_content_padding_top,
ignore = header_background_ignore_classes
)
colors <- prepare_colors(colors)
tf <- system.file("resources", "template.css", package = "xaringanthemer")
template <- readLines(tf, warn = FALSE)
template <- paste(template, collapse = "\n")
x <- whisker::whisker.render(template)
if (!is.null(extra_css)) {
x <- c(x, style_extra_css(extra_css, outfile = NULL))
}
if (is.null(outfile)) {
return(x)
}
writeLines(x, con = outfile)
invisible(outfile)
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/inst/scripts/style_xaringan_body.R |
When designing your xaringan theme,
you may have additional colors in your desired color palette
beyond those used in the accent colors of the mono and duotone styles.
The `style*()` functions in xaringanthemer
include a `colors` argument that lets you
quickly define additional colors to use in your slides.
This argument takes a vector of named colors
```r
colors = c(
red = "#f34213",
purple = "#3e2f5b",
orange = "#ff8811",
green = "#136f63",
white = "#FFFFFF"
)
```
and creates CSS classes from the color name
that set the text color — e.g. `.red` —
or that set the background color — e.g. `.bg-red`.
If you use custom CSS in your slides,
the color name is also stored in a CSS variable —
e.g. `var(--red)`.
So slide text like this
```markdown
This **.red[simple]** .white.bg-purple[demo]
_.orange[shows]_ the colors .green[in action].
```
will be rendered in HTML as
<blockquote>
This <strong><span style="color: #f34213">simple</span></strong>
<span style="color:#FFFFFF;background-color:#3e2f5b;">demo</span>
<em style="color:#ff8811">shows</em>
the colors
<span style="color:#136f63">in action</span>.
</blockquote>
Note that the color names in `colors`
need to be valid CSS names,
so `"purple-light"` will work,
but `"purple light"` will not.
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/man/fragments/_colors.Rmd |
<!-- Need to set [adding-custom-css] -->
[google-fonts]: https://fonts.google.com
<link href="https://fonts.googleapis.com/css2?family=Cabin:wght@600&family=Noto+Sans&display=swap" rel="stylesheet">
```{css echo=FALSE}
.cabin {
font-family: Cabin;
font-weight: 600
}
.noto-sans {
font-family: 'Noto Sans';
}
.font-preview {
padding: 1em;
margin-top: 1em;
margin-bottom: 1em;
border: 1px solid #dddddd;
border-radius: 3px;
font-size: 1.25em;
}
```
### Default Fonts
The default heading and body fonts used in **xaringanthemer**
are different than the xaringan default fonts.
In xaringanthemer,
[Cabin](https://fonts.google.com/specimen/Cabin)
is used for headings and
[Noto Sans](https://fonts.google.com/specimen/Noto+Sans)
for body text.
<div class="font-preview">
<p style="font-size: 1.5em" class="cabin">A Cabin in the Clearing</p>
<p class="noto-sans">Pack my box with five dozen liquor jugs. Amazingly few discotheques provide jukeboxes.</p>
</div>
These fonts are easier to read on screens and at a distance during presentations,
and they support a wide variety of languages and weights.
Another reason for the change is that the xaringan (remarkjs) default body font,
_Droid Serif_,
is no longer officially included in Google Fonts.
If you would like to use the fonts from the
[default xaringan theme](https://slides.yihui.org/xaringan/),
you can use the following arguments in your style function.
```{r eval=FALSE, echo=TRUE}
style_xaringan(
text_font_family = "Droid Serif",
text_font_url = "https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic",
header_font_google = google_font("Yanone Kaffeesatz")
)
```
### Custom and _Google Font_ Fonts
**xaringanthemer** makes it easy to use
[Google Fonts][google-fonts]
in your presentations
(provided you have an internet connection during the presentation)
or to fully specify your font files.
To use [Google Fonts][google-fonts],
set the `<type>_font_google` theme arguments --
```{r results='asis', echo=FALSE}
cat(paste0("`", tvv[grepl("_font_google$", tvv)], "`", collapse = ", "))
```
--- using the `google_font()` helper.
The help documentation in `?google_font` provides more info.
```{r eval=FALSE, echo=TRUE}
style_mono_light(
header_font_google = google_font("Josefin Slab", "600"),
text_font_google = google_font("Work Sans", "300", "300i"),
code_font_google = google_font("IBM Plex Mono")
)
```
If you set an `<type>_font_google` theme arguments,
then `<type>_font_family`, `<type>_font_weight` and `<type>_font_url`
are overwritten --
where `<type>` is one of `header`, `text`, or `code`.
To use a font hosted outside of Google fonts,
you need to provide both `<type>_font_family` and `<type>_font_url`.
For example,
suppose you want to use a code font with ligatures for your code chunks,
such as
[Fira Code](https://github.com/tonsky/FiraCode),
which would be declared with `code_font_family`.
The
[browser usage](https://github.com/tonsky/FiraCode#browser-support)
section of the Fira Code README
provides a CSS URL to be used with an `@import` statement
that you can use with the `code_font_url` argument.
```{r eval=FALSE, echo=TRUE}
style_solarized_dark(
code_font_family = "Fira Code",
code_font_url = "https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/fira_code.css"
)
```
Remember that you need to supply either
`<type>_google_font` using the `google_font()` helper
_or both_ `<type>_font_family` and `<type>_font_url`.
### Using Additional Fonts
If you want to use additional fonts for use in [custom CSS definitions][adding-custom-css],
use the `extra_fonts` argument to pass a list of URLs or `google_font()`s.
Notice that you will need to add custom CSS (for example, via `extra_css`)
to use the fonts imported in `extra_fonts`.
```{r eval=FALSE, echo=TRUE}
style_mono_light(
extra_fonts = list(
google_font("Sofia"),
# Young Serif by uplaod.fr
"https://cdn.jsdelivr.net/gh/uplaod/YoungSerif/fonts/webfonts/fontface.css",
),
extra_css = list(
".title-slide h2" = list("font-family" = "Sofia"),
blockquote = list("font-family" = "youngserifregular")
)
)
```
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/man/fragments/_fonts.Rmd |
You can install **xaringanthemer** from CRAN
```r
install.packages("xaringanthemer")
```
or you can install the development version of xaringanthemer from [GitHub](https://github.com/gadenbuie/xaringanthemer).
```r
# install.packages("remotes")
remotes::install_github("gadenbuie/xaringanthemer")
```
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/man/fragments/_installation.Rmd |
<!-- Set link to theme-settings, template-variables, theme functions -->
```{r include=FALSE}
IN_PKGDOWN <- identical(Sys.getenv("IN_PKGDOWN"), "true")
```
First, add the `xaringan-themer.css` file to the YAML header of your xaringan slides.
```yaml
output:
xaringan::moon_reader:
css: xaringan-themer.css
```
Then, in a hidden chunk just after the knitr setup chunk, load **xaringanthemer** and try one of the [theme functions][theme-functions].
````markdown
```{r xaringan-themer, include=FALSE, warning=FALSE}`r ""`
library(xaringanthemer)
style_mono_accent(
base_color = "#1c5253",
header_font_google = google_font("Josefin Sans"),
text_font_google = google_font("Montserrat", "300", "300i"),
code_font_google = google_font("Fira Mono")
)
```
````
<img src="https://raw.githubusercontent.com/gadenbuie/xaringanthemer/assets/example_mono_accent_1c5253.png" alt="Example title and normal slides using a green xaringanthemer theme" data-external="1" />
### Matching ggplot Themes
[showtext]: https://github.com/yixuan/showtext
**xaringanthemer** even provides a [ggplot2] theme
with `theme_xaringan()`
that uses the colors and fonts from your slide theme.
Built on the [showtext] package,
and designed to work seamlessly with [Google Fonts](https://fonts.google.com).
Color and fill scales are also provided
for matching sequential color scales based on
the primary color used in your slides.
See `?scale_xaringan` for more details.
More details and examples can be found in `vignette("ggplot2-themes")`.
```{r xaringanthemer-ggplot-setup, include=FALSE, eval=!IN_PKGDOWN}
style_mono_accent(
base_color = "#1c5253",
header_font_google = google_font("Josefin Sans"),
text_font_google = google_font("Montserrat", "300", "300i"),
code_font_google = google_font("Fira Mono"),
outfile = NULL
)
```
```{r theme_xaringan_demo, echo=TRUE, warning=FALSE, fig.width=13, fig.height=5.5, eval=!IN_PKGDOWN, fig.showtext=TRUE}
library(ggplot2)
ggplot(diamonds) +
aes(cut, fill = cut) +
geom_bar(show.legend = FALSE) +
labs(
x = "Cut",
y = "Count",
title = "A Fancy diamonds Plot"
) +
theme_xaringan(background_color = "#FFFFFF") +
scale_xaringan_fill_discrete()
```
```{r link-to-plot-image, echo=FALSE, eval=IN_PKGDOWN, results='asis'}
cat("")
```
### Tab Completion
**xaringanthemer** is <kbd>Tab</kbd> friendly -- [use autocomplete to explore][theme-settings] the [template variables][template-variables] that you can adjust in each of the themes!
<img src="https://raw.githubusercontent.com/gadenbuie/xaringanthemer/assets/example-rstudio-completion.gif" alt="Demonstration of argument auto-completion with RStudio" data-external="1" />
### R Markdown Template in RStudio
You can also skip the above and just create a *Ninja Themed Presentation* from the New R Markdown Document menu in RStudio.
<center>
<img src="https://raw.githubusercontent.com/gadenbuie/xaringanthemer/assets/rmarkdown-template-screenshot.png" alt="The 'New R Markdown Document' menu in RStudio" data-external="1" />
</center>
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/man/fragments/_quick-intro.Rmd |
[xaringan]: https://github.com/yihui/xaringan
Give your [xaringan] slides some style with **xaringanthemer** within your `slides.Rmd` file without (much) CSS.
<img src="https://raw.githubusercontent.com/gadenbuie/xaringanthemer/assets/examples.gif" alt="Animation previewing many xaringanthemer themes" />
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/man/fragments/_tagline-gif.Rmd |
***
[xaringan]: https://github.com/yihui/xaringan
[remarkjs]: https://github.com/gnab/remark
**xaringanthemer** was built by [Garrick Aden-Buie](https://www.garrickadenbuie.com) ([@grrrck](https://twitter.com/grrrck)).
Big thank you to [Yihui Xie](https://yihui.org), especially for [xaringan].
Also thanks to [Ole Petter Bang](http://www.gnab.org/) for [remark.js][remarkjs].
Feel free to [file an issue](https://github.com/gadenbuie/xaringanthemer/issues)
if you find a bug or have a theme suggestion -- or better yet, submit a pull request!
| /scratch/gouwar.j/cran-all/cranData/xaringanthemer/man/fragments/_thanks.Rmd |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.