library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✔ ggplot2 3.3.0           ✔ purrr   0.3.4      
## ✔ tibble  3.0.1           ✔ dplyr   0.8.99.9002
## ✔ tidyr   1.0.3           ✔ stringr 1.4.0      
## ✔ readr   1.3.1           ✔ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()

As long as Momocs2 API is not considered stable, this is more a notebook for what is intended, not for what works fine.

Patterns

Morphometric method

method <- function(x, more_args, from_col, to_col, drop_coo, ...){
  UseMethod("method")
}

method.default <- function(x, ...){
  not_defined("method")
}

method.coo_single <- function(x, more_args, ...){
  # here goes the calculation
  # that ends with
  ... %>% 
    coe_single() %>% 
    .append_class("method_single")
}

method.coo_list <- function(x, more_args, ...){
  # something on the lines of
  x %>% 
  purrr::map(method, more_args) %>% 
  coe_list() %>% 
  .append_class("method_list")
}

method.mom_tbl <- function(x, more_args, from_col, to_col, drop_coo=TRUE, ...){
  # tidyeval
  from_col <- enquo(from_col)
  to_col <- enquo(to_col)

  res <- dplyr::pull(x, !!from_col) %>% method(more_args)
  res <- dplyr::mutate(x, !!to_col := res)

  if (drop_coo)
    res <- dplyr::select(res, -(!!from_col))
  res
}

Inverse morphometric method

Calibrate morphometric method

In Momocs2 their names follow this pattern: method_cal_flavour, eg efourier_cal_harmonicpower