R/utils.R

Defines functions format_colnames glue2 list_to_df data_list to_ch0 ceiling100 logit .rndm_seed

.rndm_seed <- function() as.integer(Sys.time())

.max_int <- .Machine$integer.max

logit <- function(x) log(x / (1 - x))

ceiling100 <- function(x) ceiling(x/100)*100

to_ch0 <- function(x){
  if(!length(x) || x == "")
    x <- character(0)
  x
}

data_list <- function(x){
  list(nObs = nrow(x),
       nStation = length(unique(x$Station)),
       Distance = x$Distance,
       Detects = x$Detects,
       Pings = x$Pings,
       Station = x$Station)
}

list_to_df <- function(x){
  x <- as.data.frame(x)
  x$Station <- as.factor(x$Station)
  x
}

glue2 <- function(x){
  as.character(glue::glue(x, .open = "<<", .close = ">>",
                          .envir = parent.frame()))
}

format_colnames <- function(x){
  nm <- names(x)
  nml <- strsplit(nm, "_", fixed = TRUE)
  nml <- lapply(nml, function(x){
    x <- tools::toTitleCase(x)
    paste(x, collapse = "")
  })
  names(x) <- unlist(nml)
  x
}
Freshwater-Fish-Ecology-Laboratory/detrange documentation built on Oct. 30, 2024, 1:10 p.m.