R/util_view_file.R

Defines functions util_view_file

Documented in util_view_file

#' View a file in most suitable viewer
#'
#' @param file the file to view
#'
#' @return
#' `invisible(file)`
util_view_file <- function(file) {
  viewer <- getOption("viewer")
  if (is.null(viewer)) { # nocov start
    # Viewer stuff cannot be tested w/o a GUI
    if (requireNamespace("rstudioapi", quietly = TRUE) &&
        (exists("viewer", asNamespace("rstudioapi"), mode = "function")) &&
        (exists("isAvailable", asNamespace("rstudioapi"), mode = "function")) &&
        rstudioapi::isAvailable()) {
      rstudioapi::viewer(file)
    } else {
      browseURL(paste0("file://", file))
    }
  } else { # nocov end
    viewer(file)
  }
  invisible(file)
}

Try the dataquieR package in your browser

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

dataquieR documentation built on July 26, 2023, 6:10 p.m.