Skip to content

Instantly share code, notes, and snippets.

@tiernanmartin
Created July 21, 2018 23:48
Show Gist options
  • Save tiernanmartin/71b44f40567edfdb70c73b5e00afa7c1 to your computer and use it in GitHub Desktop.
Save tiernanmartin/71b44f40567edfdb70c73b5e00afa7c1 to your computer and use it in GitHub Desktop.
A template for R/utils.R in a package
#' @title A set of generic helpful functions
#' @description General purpose functions to make working in R easier.
#' @name utils
#' @import purrr
NULL
#' @rdname utils
#' @export
not_sfc <- function(x) !any(class(x) %in% 'sfc')
#' @rdname utils
#' @export
first_not_na <- function(x){
if(all(sapply(x,is.na))){
methods::as(NA,class(x))
}else{
x[!sapply(x,is.na)][1]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment