R/cat_filesWarnLong.R

Defines functions cat_filesWarnLong

cat_filesWarnLong <- function(...,
                              file = "",
                              sep = " ",
                              fill = FALSE,
                              labels = NULL,
                              append = FALSE) {
  catRes <- tryCatch(
    cat(
      ...,
      file = file,
      sep = sep,
      fill = fill,
      labels = labels,
      append = append
    ),
    error = function(e) {
      if (.Platform$OS.type == "windows") {
        if (nchar(file) > 254) {
          longErrortxt <- paste0(
            "Cannot write to the file\n",
            file,
            "\ndue to over-long path. Original error reported:\n",
            e$message
          )
          stop(longErrortxt)
        } else {
          stop(e)
        }
      } else {
        stop(e)
      }
    },
    warning = function(w) {
      if (any(grepl("cannot open file", w$message)) &&
          nchar(file) > 254 &&
          .Platform$OS.type == "windows") {
        longErrortxt <- paste0("Cannot write file\n", file,
                               "\ndue to over-long path.")
        stop(longErrortxt)
      } else {
        warning(w)
      }
    }
  )
}

Try the Certara.NLME8 package in your browser

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

Certara.NLME8 documentation built on Oct. 16, 2024, 1:09 a.m.