I have a string with backslash and I want to remove them.
test = "m \"#\""
Have tried the following but none works :
gsub( "\\\\", "", test )
gsub( "\\\\", "", test, fixed = T )
gsub( "\\", "", test )
gsub( "\\", "", test, fixed = T )
Have looked into similar questions but none of the solutions work.
Replace single backslash in R Remove Single Backslash String R
Edit : Actually this text is going to be passed in system() function to run a mosquitto client. User will give various parameters as input and the command will be created up on the fly.
The full command looks like this : mosquitto_sub -h test.mosquitto.org -q 0 -k 60 -t \"#\"
However it is expected to be like this : mosquitto_sub -h test.mosquitto.org -q 0 -k 60 -t "#"
Otherwise system()
does not take it. Hence is the requirement to remove the backslaches.
The parameters 0
and 60
and #
are supplied by user. Hence using paste0() to make this string. After the string is created the backslashes comes up.
The string given in text here is to create a reproducible and short example here.