docs/CustomFunctions.md

This is a slightly out of date and needs updating, please check back later!

Creating custom functions

Adding a function is slightly more involved. First make sure the function (or the package the function is in) is already sourced. Then add the function by name, also specifying the module as either 'ClickDetector' or 'WhistlesMoans'. If you do not specify, you will be asked to choose. addFunction will also ask the use to set the value for any parameters that are arguments to the function you provide, except for parameters named "data" or "calibration". In this example, the user would be ask to set values for "a", then "b", and would be told that the default for "a" is 1, and that there is not a default value for "b".

testFunction <- function(data, a=1, b) {
    ### Do smart stuff here
}
myPrs <- addFunction(myPrs, testFunction, module='ClickDetector')    

For the ClickDetector, there are a couple of requirements for this function. The function should have an input called "data", and it should expect that this "data" input is a list with two parts: data$wave containing the click waveform, and data$sr containing the sample rate of this click. The waveform will have one column for each channel. The output of this function should be a dataframe that has one row for each channel, there can be as many columns as you like. addFunction will do a quick check of the function you try to add on a sample click.

For WhistlesMoans functions, the function should have an input "data" that is a list with two parts: data$freq and data$time. freq should contain the contour of the whistle, stored as a vector of frequencies. time should be the time in seconds at each of these frequencies. The output of this function should be a dataframe with one row, or an object that is easily coerced to a dataframe (e.g. a list where all elements have length 1).



TaikiSan21/PAMr documentation built on Nov. 15, 2020, 9:46 p.m.