Add your own custom R functions or variables with R Script
You might want to use your own R functions as part of your data wrangling steps. This is an introduction for such case. If you want to write your own R functions to extract data, please refer to Write R Script for Data.
You can write your functions in an R script and register it to your project, then you can start calling the functions just like any other functions.
Example - alpha function from psych package
This is an example to use alpha function from psych R package from Exploratory Desktop.
Install Required Package
In this example, psych is already installed as a default dependency package but the function you want to use might be from a package that we don't install as default. In that case, please install the package following this instruction.
get_alpha <- function(df, attr = "total", ...){
num_df <- df %>%
dplyr::select_if(is.numeric)
# class of first arg in psych::alpha must be only data.frame class
class(num_df) <- "data.frame"
alpha_obj <- psych::alpha(num_df, ...)
alpha_obj[[attr]]
}