0

How do I ensure I read my files using the exact file path as provided by Windows? For instance, this works:

myimg<-image_read("C:\\Users\\Nelson\\Desktop\\hypo.jpg")

But Not this:

myimg<-image_read("C:\Users\Nelson\Desktop\hypo.jpg")

What is the reason behind this?

E_net4
  • 27,810
  • 13
  • 101
  • 139
NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • 1
    *why* questions are very broad (IMO), but I think that [seancarmody's answer](https://stackoverflow.com/a/11806550/1286528) in linked post answers it. – pogibas Dec 20 '18 at 13:25
  • 1
    @NelsonGon From R 4.0.0 raw strings are supported. See [Escaping backslash () in string or paths in R](https://stackoverflow.com/questions/14185287/escaping-backslash-in-string-or-paths-in-r/63078969#63078969) – Henrik Aug 11 '20 at 16:13

1 Answers1

2

In R, a single backslash is an escape character, and using it for directory paths will always produce an error: https://kb.iu.edu/d/azzp

For conversion see: Efficiently convert backslash to forward slash in R

tomaz
  • 493
  • 4
  • 13