R/ana_set_resultmethod.R

Defines functions set_resultmethod set_plotformula

# ---------
#' set function to calculate new results based on cursor results
#'
#' @param stimname  the name of the stimulus to operate on, or a series object 
#' @param resultname the name of the new result column  
#' @param fun a function that takes cursor results as a dataframe, then modyfies and returns it
#'
#' @return dataframe (the modified cursor results)
#' @export
#' @examples
#' # make a new result column "new1" which contains all zeroes: 
#' # set_resultmethod("hERG", "new1", function(df){df$new=0;df})
set_resultmethod <- function(stimname, resultname, fun) {
  st<-get_stimname(stimname)
  if(is.null(CURSORS[[st]]$resultmethods))
    CURSORS[[st]]$resultmethods<<-list()
  CURSORS[[st]]$resultmethods[[resultname]] <<- fun
}


#' set formula to plot cursor results in plot2
#'
#' @param st  same as set_cursor 
#' @param formula a formula for plotting the results
#'
#' @return dataframe (the modified cursor results)
#' @export

set_plotformula <- function(st, formula) {
  st<-get_stimname(st)
  CURSORS[[st]]$plotformula <<- formula
}
tdanker/ephys2 documentation built on Aug. 11, 2019, 12:12 p.m.