Project: s41467-024-44813-2 | Function: iCER (r)

system: You are an expert R programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow R best practices and maintain consistent code style.
Return **only** the complete R function code.

user: Complete this R function:

**DESCRIPTION:** Calculates compositional-level environmental response (iCER) indicator to quantify thermal responses of dissolved organic matter assemblages. Main innovation of the paper - integrates molecule-specific environmental responses (MER) into assemblage-level indicator.

**KEY TERMS:** {
  "data_ra": "relative abundance of molecules",
  "envi": "environmental variables (temperature)",
  "MER": "molecule-specific environmental response",
  "spearman.cor": "Spearman correlation coefficient ρ",
  "functcomp": "weighted average calculation"
}

**CONTEXT CODE:** #' @title The Indicator of Compositional-Level Thermal Responses (iCER)
#' @description The iCER function calculates the Indicator of Compositional-Level Thermal Responses (iCER) based on environmental data (`envi`) and molecular relative abundance data (`data_ra`).
#' @param data_ra A data frame containing the relative abundance of molecules, where rows represent samples and columns represent different molecules.
#' @param envi A data frame containing environmental variables associated with each sample. The rows should correspond to the samples in `data_ra`, and it should include the variable(s) specified in `vars_list`.
#' @param prop The proportion of the dataset to be used for MER (Molecule-specific thermal responses) calculation. This controls how much of the original dataset is sampled for analysis. Default: 0.8.
#' @param Temp_num The number of temperature levels to randomly select when generating independent data sets.
#' @param end_n Ensures that each sample appears at least this many times in the iCER datasets during random data partitioning. Increasing this value will result in a greater number of permutations. Default: 10.
#' @param cutoff The threshold for retaining molecules observed in a specified proportion of the samples within the MER dataset. Molecules present in less than this proportion of samples will be excluded from the MER calculation. Default: 0.3.
#' @param vars_list The name or list of environmental variables (such as temperature) to be used in the correlation analysis. Default: 'Temperature'.
#' @param significant_only A boolean indicating whether to calculate iCER using only molecules with significant MERs. If set to TRUE, only molecules with significant correlations (based on `p_value_threshold`) are included. Default: FALSE.
#' @param p_value_threshold The significance level for determining whether a molecule's correlation is considered significant. Default: 0.05
#' @return A list containing the following components:
#' \itemize{
#'   \item `MER`: A data frame of MER values for molecules.
#'   \item `CER_all_out`: A data frame of iCER values calculated from all molecules (if `significant_only = FALSE`).
#'   \item `CER_sig_out`: A data frame of iCER values calculated from molecules with significant MERs (if `significant_only = TRUE`).
#'   \item `CER_mean`: A data frame of the mean iCER value for each sample.
#' }
#' @examples 
#' \dontrun{
#' if(interactive()){
#'  # Example of calculating iCER using all molecules
#'  result_all <- iCER(data_ra, envi, significant_only = FALSE)
#'  
#'  # Example of calculating iCER using only significant molecules
#'  result_sig <- iCER(data_ra, envi, significant_only = TRUE, p_value_threshold = 0.05)
#'  }
#' }
#' @seealso 
#'  \code{\link[reshape2]{melt}}
#'  \code{\link[FD]{functcomp}}
#' @rdname iCER
#' @export 
#' @importFrom reshape2 melt
#' @importFrom FD functcomp

iCER <- function(data_ra, envi, prop = 0.80, Temp_num, end_n = 10, cutoff = 0.3, vars_list = "Temperature", significant_only = FALSE, p_value_threshold = 0.05) {
  stop("Function implementation has been masked")
}

Complete the function implementation replacing "stop("Not implemented")".