R/join_function.R

Defines functions join_function

Documented in join_function

#' Join function
#'
#' Safely performs a left join between two dataframes.
#' @param df1 First dataframe.
#' @param df2 Second dataframe.
#' @param condition Column in which the two datframes will be joined. Can be a single string or a vector.
#' @return Dataframe.
#' @export
join_function <- function(df1, df2, condition){
  df <- df1 %>%
    tryCatch(
      expr = left_join(.,df2, by = condition),
      error = function(e){
        message('Join failed!')
        stop(e)
      }
    )
  return(df)
}

Try the DIETCOST package in your browser

Any scripts or data that you put into this service are public.

DIETCOST documentation built on June 8, 2025, 1:51 p.m.