0

I have following folder structure.

C:\Folders\Subfolder\Sub-Subfolder\Sub-Sub-Subfloder and also have file called grphics01.pdf and I want to save grphics01.pdf file to this C:\Folders\Subfolder\Sub-Subfolder\Sub-Sub-Subfloder folder.

My current working directory is different than this folder structure.

When I am using following code:

directory <- "C:\\Folders\\Subfolder\\Sub-Subfolder\\Sub-Sub-Subfloder\\"
ggsave(filename = here(directory, "graphics01.pdf"), width = 30, height = 20, units = "cm", 
        device = cairo_pdf())

I am getting this error:

Error in grDevices::pdf(file = filename, ..., version = version) : 
cannot open file 'C:\Folders\Subfolder\Sub-Subfolder\Sub-Sub-Subfloder\/graphics.pdf'

As per my understanding, Sub-Sub-Subfloder\/graphics.pdf the front-slash in-front of the file name is causing the error.

Is there any way can I convert this front-slash to a back-slash?

I have to resolve the issue by using "here" package and defining

ggsave(path = directory, filename = "graphics01.pdf, device = pdf)

But I am getting the same eror.

book1001
  • 3
  • 2
  • 1
    Try without the last "\\", i.e. `directory <- "C:\\Folders\\Subfolder\\Sub-Subfolder\\Sub-Sub-Subfloder"`. – stefan Dec 22 '22 at 14:38
  • @stefan still getting the same error, the system is putting a front-slash in-front of the file name `/graphics01.pdf` – book1001 Dec 22 '22 at 14:55
  • Hm. Weird. The forward slash is not the issue. I just checked on a Windows machine and worked fine. Perhaps you you check that the folder exists, e.g. using `dir(directory)`? At least `Subfloder` looks like a typo to me. – stefan Dec 22 '22 at 15:07
  • @stefan, the folder exists and it is not a typo `C:\Folders\Subfolder\Sub-Subfolder\Sub-Sub-Subfloder/graphics01.pdf` this is returning as the full path. Every level it is back slash only in front of the filename there is front slash. – book1001 Dec 22 '22 at 15:17

0 Answers0