Replace illegal characters for file operations in linux server in a character string

Solution 1:

The R package {fs} provides the function fs::path_sanitize(). You probably want to check it out. https://fs.r-lib.org/reference/path_sanitize.html