R/createLaTeXparameters.R

Defines functions createLaTeXparameters

Documented in createLaTeXparameters

#' Takes an R list and creates commands for each of the keys.
#'
#' @param key.list list of keys and values. 
#' @param parameter.file.location is the location of the parameter file.
#' @param append is a boolean for whether we shoudl append the parameter file. 
#' @return None - run for side-effects.  
#' @export

createLaTeXparameters <- function(key.list, parameter.file.location, append = FALSE){
    createCommand <- function(command.name, value) paste("\\newcommand{\\", command.name, "}{", value, "}", sep="")
    command.list <- sapply(names(key.list), function(key) createCommand(key, key.list[[key]]))
    if(append){
        fileConn <- file(parameter.file.location, open = "a")
        writeLines(command.list, fileConn)
        close(fileConn)
    } else {
        writeLines(command.list, parameter.file.location)
    }
}
johnjosephhorton/JJHmisc documentation built on May 19, 2019, 5:15 p.m.