Skip to content

Instantly share code, notes, and snippets.

@sbalci
Forked from matt-dray/check-rproj-dupes.R
Created July 9, 2022 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbalci/e5b2c0a7545b04d543b8abe620a56052 to your computer and use it in GitHub Desktop.
Save sbalci/e5b2c0a7545b04d543b8abe620a56052 to your computer and use it in GitHub Desktop.
Check for open RStudio Projects that have the same name (macOS only for now)
check_rproj_dupes <- function() {
os <- .Platform$OS.type
if (os == "unix") {
ps_out <- system("ps -e", intern = TRUE)
ps_rproj <- ps_out[grepl(".Rproj", ps_out)]
ps_split <- strsplit(ps_rproj, "\\s")
rproj_paths <- lapply(ps_split, function(x) x[grepl(".Rproj$", x)])
rproj_basenames <- lapply(rproj_paths, basename)
rproj_dupes <- unlist(rproj_basenames[duplicated(rproj_basenames)])
}
if (os == "windows") {
stop("Sorry, check_rproj_dupes() doesn't work on Windows yet :-(")
}
if (length(rproj_dupes) > 0) {
warning(
"You've got open RStudio Projects with the same name:\n",
paste("-", rproj_dupes, collapse = "\n"),
call. = FALSE
)
}
}
check_rproj_dupes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment