Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't convert back slashes to forward slashes [duplicate]

Tags:

r

readr

Im studying about data but there is a problem. There is a lot of data that I use to study but everytime I want to load the data with read_csv() I use a lot of time to change \ to /.

My files are locaten like this C:\\Users\\Me\\Desktop\\Data\\hotel_bookings.csv

So I can not do;

x <- "C:\Users\Me\Desktop\Data\hotel_bookings.csv"

Because my folder directory saves as \ not as \\

One of the solitions I found is

hotel <- read_csv(file.choose()) 

The other one is also

path <- "C:\\Users\\Me\\Desktop\\Data\\hotel_bookings.csv"
path <- normalizePath(path)
hotel <- read_csv(path)

but still takes time to insert an extra \.

Need an easier way to get my file location that contains all /

like image 584
Ozan Tivriz Avatar asked Oct 26 '25 15:10

Ozan Tivriz


1 Answers

Since R 4.0.0, you can use raw character constants (mentioned on r-devel NEWS):

There is a new syntax for specifying raw character constants similar to the one used in C++: r"(...)" with ... any character sequence not containing the sequence ‘⁠)"⁠’. This makes it easier to write strings that contain backslashes or both single and double quotes.

x <- r"(C:\Users\Me\Desktop\Data\hotel_bookings.csv)"
like image 146
Robby Cornelissen Avatar answered Oct 29 '25 05:10

Robby Cornelissen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!