R/util_view_file.R

Defines functions util_view_file

#' View a file in most suitable viewer
#'
#' @param file the file to view
#'
#' @return
#' `invisible(file)`
#'
#' @family system_functions
#' @concept reporting
#' @noRd
util_view_file <- function(file) {
  viewer <- getOption("viewer")
  if (is.null(viewer)) { # nocov start
    if (!identical(Sys.getenv("TESTTHAT"), "true")) {
      # Viewer stuff cannot be tested w/o a GUI
      if (util_really_rstudio() &&
          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 Jan. 8, 2026, 5:08 p.m.