# A little function that just concatenates paths (as strings) # to produce a "path" to some file/directory path_c <- function(path1, ..., sep) { if (missing(sep)) { # Note that the directory separator depends on the OS # (e.g. sep = "\\" on Windows) sep <- switch(.Platform$OS.type, unix = "/", windows = "\\" ) } paste(path1, ..., sep = sep) } # # This one is only useful from within RStudio # editcode <- function(filename, dir, ...){ if (missing(dir)) dir <- getwd() file <- path_c(dir, filename, ...) if (file.exists(file)) { file.edit(file) } else { file.choose() } } # # Check that a variable is defined # (from stackoverflow # https://stackoverflow.com/questions/9368900/how-to-check-if-object-variable-is-defined-in-r # ) # is.defined <- function(sym) { sym <- deparse(substitute(sym)) env <- parent.frame() exists(sym, env) }