R/utils.R

Defines functions strip_vsi remote_src tmp_tbl_name tbl_name

tbl_name <- function(path) {
  if (length(path) > 1) {
    path <- path[[1]]
  }
  # sql-safe names based on path
  name <- basename(tools::file_path_sans_ext(path))
  name <- gsub("[^a-zA-Z0-9]", "_", name)
  ## what if it starts with a digit
  if (grepl("^[0-9]", name)) name <- paste0("file_", name)
  name
}

tmp_tbl_name <- function(n = 15) {
  paste0(sample(letters, n, replace = TRUE), collapse = "")
}

remote_src <- function(conn) {
  dbplyr::remote_src(conn)
}

strip_vsi <- function(path) {
  if(grepl("^/vsi\\w+/", path)) {
    path <- gsub("^/vsi\\w+/", "", path)
  }
  path
}

Try the duckdbfs package in your browser

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

duckdbfs documentation built on April 11, 2025, 5:52 p.m.