is.safeFileName: Verify that a fileName is safe for use in shell commands.

Description Usage Arguments Value Valid names

View source: R/systemRunUtils.R


Validates filenames for use in system commands. Allows for either blacklist and whitelist filtering, and independently controls several characters in common use in filenames that could be dangerous in some contexts. Optionally may also require a filename to exist or not to exist.


is.safeFileName(names, exists = NULL, weak = FALSE, okSpace = TRUE,
  okTilde = TRUE, okBackslash = FALSE, okComma = FALSE, okColon = FALSE)



A vector of filenames to check.


NULL Can set TRUE to ensure file exists, or FALSE to ensure file does NOT exist. (Note, don't rely on this as only error check for reading/writting file as that introduces a race condition).


default this is FALSE and validation is done using white-listed characters. Set TRUE to do validation using blacklisted characters. See Valid names below for additional info


Set TRUE to ban a space. Allows " " by default.


Set TRUE to ban a tilde. Allows "~" by default (anywhere!).


Set TRUE to allow a backslash. No \ are allowed by default.


Set TRUE to allow a comma. No , are allowed by default.


Set TRUE to allow a colon. No : are allowed by default.


Returns a vector of booleans the same length as the input names, TRUE if the file is safe, FALSE if it fails any test.

Valid names

Filtering at a single character level will catch most bad names:

Always bad ` $ ( ) | ; & > <
Always ok A:Z a:z 0:9 _ . - /
Can set bad " " (space)
Can set bad ~ (tilde will be allowed anywhere)
Can set ok \ , :
May not start with + -

In addition, no filename may contain either " -" or " +" ( the - or + character preceded by a space.) This prevents injecting new options.

By default, whitelist validation is used. Files may only use charcters explicitly allowed. Can switch to blacklist validation by setting weak= TRUE, which allows any character not explicitly banned.

jefferys/FusionExpressionPlot documentation built on May 19, 2019, 3:59 a.m.