1dir.exists <- function(x) {
2  res <- file.exists(x) & file.info(x)$isdir
3  stats::setNames(res, x)
4}
5
6pkg_path <- function(path = ".") {
7  rprojroot::find_root("DESCRIPTION", path)
8}
9
10pkg_name <- function(path = ".") {
11  desc::desc_get("Package", pkg_path(path))[[1]]
12}
13
14gcc_arch <- function() {
15  if (Sys.getenv("R_ARCH") == "/i386") "32" else "64"
16}
17
18is_windows <- function() {
19  .Platform$OS.type == "windows"
20}
21
22is_dir <- function(x) {
23  isTRUE(file.info(x)$isdir)
24}
25
26# This is tools::makevars_user, provided here for backwards compatibility with older versions of R
27makevars_user <- function () {
28  m <- character()
29  if (.Platform$OS.type == "windows") {
30    if (!is.na(f <- Sys.getenv("R_MAKEVARS_USER", NA_character_))) {
31      if (file.exists(f))
32        m <- f
33    }
34    else if ((Sys.getenv("R_ARCH") == "/x64") && file.exists(f <- path.expand("~/.R/Makevars.win64")))
35      m <- f
36    else if (file.exists(f <- path.expand("~/.R/Makevars.win")))
37      m <- f
38    else if (file.exists(f <- path.expand("~/.R/Makevars")))
39      m <- f
40  }
41  else {
42    if (!is.na(f <- Sys.getenv("R_MAKEVARS_USER", NA_character_))) {
43      if (file.exists(f))
44        m <- f
45    }
46    else if (file.exists(f <- path.expand(paste0("~/.R/Makevars-",
47            Sys.getenv("R_PLATFORM")))))
48      m <- f
49    else if (file.exists(f <- path.expand("~/.R/Makevars")))
50      m <- f
51  }
52  m
53}
54
55last_char <- function(x) {
56  l <- nchar(x)
57  substr(x, l, l)
58}
59
60cat0 <- function(..., sep = "") {
61  cat(..., sep = "")
62}
63