Copying files with R Package on Windows - Access is Denied - file.path()

I am attempting to fix the slidex package (converts Powerpoint [.pptx] to Xaringan) so it works on Windows. I keep hitting Access is denied errors when this line runs:

file.rename(file.path(basepath, "xml", "ppt", "media"),
                file.path(basepath2, "assets", "img"))

Warning message:
In file.rename(file.path(basepath, "xml", "ppt", "media"), file.path(basepath2, :
cannot rename file 'C:\Users\rick2\AppData\Local\Temp\RtmpueUFV7/RCommunityOrg_useR2021/xml/ppt/media' to 'C:\Users\rick2\AppData\Roaming/RCommunityOrg_useR2021/assets/img', reason 'Access is denied'

I see both folders exist and the first has file. file.copy instead of file.rename also fails.

Now, I just discovered that adjusting every folder object with code resembling the following solves the problem (borrowed from R Markdown's code),

path <- gsub('/', '\\\\', path)

However, must I do this every time a folder is created with file.path()?

The filenames you generate have mixed forward and backward slashes.
Which code do you use to set the basepath variables?
Make sure it generates only forward slashes.
If it is unfeasible to do that, then use a gsub trick such as described.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.