Issue
I have a string name
that will generate a file name as paste(name, ".pdf", sep="")
This file will then be moved to another directory after completion.
I would like to proactively avoid any characters in name
that might cause errors in file operations like whitespace
, \
, []
, other characters like !"§$%&/()=
and any others by replacing them. Special characters in German like öäüß
should not cause problems and should be allowed.
Since name is a user input I can't know beforehand what a user might input as character which will then cause problems.
Which characters will give me errors?
Is there any solution or regex to do this without explicitly running each character with sub
for example df$name<-sub(" ", "_", df$name)
Solution
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
Answered By - Seb Answer Checked By - Dawn Plyler (WPSolving Volunteer)