Cannot install packages with tempfile error

I originally had the error:

Error in tempfile(pattern = ".rstudio-", tmpdir = lib) : 
  unable to translate 'C:/Users/levih/OneDrive/<U+6587><U+4EF6>/R/win-library/4.1' to native encoding
In addition: Warning message:
In base::list.dirs(.libPaths(), full.names = FALSE, recursive = FALSE) :
  unable to translate 'C:/Users/levih/OneDrive/<U+6587><U+4EF6>/R/win-library/4.1' to native encoding
Error in tempfile(pattern = ".rstudio-", tmpdir = lib) : 
  unable to translate 'C:/Users/levih/OneDrive/<U+6587><U+4EF6>/R/win-library/4.1' to native encoding
In addition: Warning messages:
1: In list.files(.rs.uniqueLibraryPaths(), full.names = TRUE) :
  unable to translate 'C:/Users/levih/OneDrive/<U+6587><U+4EF6>/R/win-library/4.1' to native encoding
2: In list.files(.libPaths()) :
  unable to translate 'C:/Users/levih/OneDrive/<U+6587><U+4EF6>/R/win-library/4.1' to native encoding
3: In list.files(.libPaths()) :
  unable to translate 'C:/Users/levih/OneDrive/<U+6587><U+4EF6>/R/win-library/4.1' to native encoding

but after I changed something:

R_LIBS_SITE="C:\\Program Files\\R\\R-4.1.0\\library"

the error becomes:

Error in tempfile(pattern = ".rstudio-", tmpdir = lib) : 
  unable to translate 'C:/Users/levih/OneDrive/<U+6587><U+4EF6>/R/win-library/4.1' to native encoding

How can I solve the problem?

By the way I referenced to Andres' Blog (rbind.io)

This is due to the known issues of R with synced folders and non-ASCII characters in the library path, the solution would be to set your package in a different location as apparently you are trying to do but it seems to me you haven't changed your package library successfully, what is the output of running .libPaths() on the R console?

The output is like:

> .libPaths()
[1] "C:/Users/levih/OneDrive/文件/R/win-library/4.1"
[2] "C:/Program Files/R/R-4.1.0/library"

I have looked for some posts but it seems that there's no the same problem,
and I don't know what this means:

Error in tempfile(pattern = ".rstudio-", tmpdir = lib) : 
  unable to translate 'C:/Users/levih/OneDrive/<U+6587><U+4EF6>/R/win-library/4.1' to native encoding

What's tempfile?
I searched tempfile(pattern = ".rstudio-", tmpdir = lib) on Goolge and no similar results came out.


I deleted my "R" file in the recycle bin on OneDrive but the output is still the same.

Hey guys, I have solved the problem.
Here is the video:
How do I change the default library path for R packages [Set R environment at start up permanently] - YouTube
After you finish it, open as administrator and you can install.

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.