R/drop_geometry_column.R

Defines functions drop_geometry_column

Documented in drop_geometry_column

#' Removes geometry column in sf data frames
#'
#' Replicates the functionality of  `sf::st_drop_geometry()` without depending on the `sf` package.
#'
#' @inheritParams collinear
#'
#' @return data frame
#' @family data_preparation
#' @autoglobal
#' @author Blas M. Benito, PhD
#' @export
drop_geometry_column <- function(
    df = NULL,
    quiet = FALSE
    ){

  #remove geometry column from df
  sf.column <- attributes(df)$sf_column

  if(!is.null(sf.column)){

    if(quiet == FALSE){

      message("\ncollinear::drop_geometry_column(): dropping geometry column from 'df'.")

    }

    df <- as.data.frame(df)
    df[[sf.column]] <- NULL
    attr(df, "sf_column") <- NULL

  }

  df

}

Try the collinear package in your browser

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

collinear documentation built on April 12, 2025, 1:36 a.m.