R/plot.raw.n.fit.R

Defines functions plot.raw.n.fit

Documented in plot.raw.n.fit

#' plot raw curve and fit curve
#'
#' @param df
#' @param config
#' @param mark
#' @param screen.n
#'
#' @return
#' @export
#'
#' @examples
plot.raw.n.fit <- function(df, config, mark, screen.n) {
  # VER 1.3.0
  screen(screen.n)
  erase.screen()
  flush.console()
  par(mar = config$margin)
  mode <- config$mode
  #     df <- NULL
  #     try({
  #         df <- read.csv(path, skip = skip)
  #     }, silent = T)
  #     if (is.null(df)) {
  #         cat(sprintf(
  #             'plot.raw.n.fit() > File access failed @ \n %s', basename(path)
  #         ))
  #         return(NULL)
  #     }
  #
  fc <- NULL
  try({
    fc <- fit.curve(df[,2], mode, config)
  }, silent = T)
  if (is.null(fc)) {
    cat(
      sprintf(
        'plot.raw.n.fit() > fit.curve() > Curve fit failed @ \n %s', basename(path)
      )
    )
    return(NULL)
  }
  plot(
    df[,1], df[,2],
    type = 'l',
    col = 'blue',
    main = mark,
    xlab = 'Voltage',
    ylab = 'Current'
  )
  par(new = T)
  plot(
    df[,1], fc,
    type = 'l',
    col = 2,
    axes = F,
    main = '',
    xlab = '',
    ylab = ''
  )
  par(new = F)
}
yanxianUCSB/yxhelper documentation built on April 20, 2020, 4:09 p.m.