R/parameter_write.R

Defines functions parameter_write

Documented in parameter_write

#' Write the parameters used in the simulation
#' @description When saving the simulated result to a text file, this function writes 
#' the parameters used. Objects other than essential parameters are wiped out.
#' @name parameter_write
#' @param x A data frame to write
#' @param file_name text file name
#' @return ... 
#' @examples
#' 
#' @export


parameter_write <- function (
  result,
  parameter_list,
  file_name = "data/example001.txt"
) {
  # File name
#  file_name <- paste0(path, treatment_name, "-", sprintf("%03d", r),".txt")
  file_opened <- file(file_name)
  
  # Write parameter
  writeLines(unname(sapply(parameter_list, function(x) paste0("# ", x, " = ", get(x, envir = .GlobalEnv)))), file_opened)
  
  # Append result to text file
  fwrite(result, file = file_name, append = T, col.names = T)

  # Close file
  close(file_opened)
}
Chang-Yu-Chang/MigrationCommunity documentation built on April 25, 2019, 8:55 a.m.