R/write_quote.R

Defines functions write_quote

Documented in write_quote

#' write_quote
#'
#' @return file path of `rscript`
#' @export
write_quote <- function(rscript, outfile,
                        header = c("#! /usr/bin/Rscript \nlibrary(ChinaWater); library(lubridate); print(getwd());")) {
  if (typeof(rscript) == "language") { # quoteobj
    scripts <- deparse(rscript)
    nline <- length(scripts)

    scripts <- gsub("^ {4}", "", scripts[2:(nline - 1)]) %>% c(header, .)

    writeLines(scripts, outfile)
    # change rscipt to filepath
    rscript <- outfile
  }
  rscript
}
rpkgs/curlR documentation built on Jan. 30, 2023, 7:26 p.m.