0

I'm trying to import a file in spotfire depending on the path entered by the user.

I'm using a data function (R script). As you know, in R all "\" are not recognized and consequently must be replaced by : "/".

If the user is entered in the input filed the path with "/" as delimiter : the file is well importing.

I would like to adapt my R script in order to permit users to paste his original path (with "\") and then to replace with "/".

I don't understand well why it seem like we can't use R function like paste on the variable containing the input field (see the following pictures).

Note that path is the name of the document proporty (the input filed) and the script has been tested with and without the as.character line.

Can someone help me?

Any help would be appreciated :)

Auré
  • 161
  • 1
  • 11

1 Answers1

0

can't you use simple regex to replace '\' with '/'? Something like

sub('\', '/', str)

(You probably need to escape this)

lukas-reineke
  • 3,132
  • 2
  • 18
  • 26
  • It doesn't work. If I try to use the path including "\" character as following : path2 = paste("C:\Users\Name\Desktop\file.csv",sep="") , I have an error before performing the gsub statement Error: '\U' used without hex digits in character string starting ""C:\U" – Auré Mar 01 '18 at 16:25
  • 1
    Yes, you will have to replace the '\' before running `paste()` Take a look [at this question](https://stackoverflow.com/questions/8425409/file-path-issues-in-r-using-windows-hex-digits-in-character-string-error) – lukas-reineke Mar 01 '18 at 16:31
  • Thanks for your help. I'll take a look ! – Auré Mar 02 '18 at 07:31