A Problem of installing R package in OneDrive
Many people face the following problem during installing R packages on Windows:
“unable to translate ‘C:/Users/username/OneDrive/<U+6587><U+6863>/R/win-library/4.1’ to native encoding”
The username is the user name of your computer. This problem is caused because R cannot install packages in OneDrive on Windows. Let’s check the R packages installation path. Open RGui and type:
.libPaths()
![](https://cdn-images-1.medium.com/max/800/1*iq2JTYS3cwFAj7NFVe3oMg.png)
You will see something in the above screenshot, where it shows that the first path (or default path) is “C:/Users/username/Onedrive/…”.
If we change this path, the problem will be solved. Let’s see how to do it in the following sections.
1. Change permission of editing Rprofile
(1) Navigate to R base installation path
The default path is usually “C:\Program Files\R\R-4.1.1\library\base\
”. If you install R in other Disk, you just go to find it.
(2) Change the permission of R subfolder
Right click R subfolder in the base folder, and then click Properties.
![](https://cdn-images-1.medium.com/max/800/1*1bxL1iY8LfydjmK4GafV6g.png)
Select Security, and then click User (DESKTOP JRUIS9V\User) followed by clicking Edit.
![](https://cdn-images-1.medium.com/max/800/1*jvtJUhJkrf1tn5RIWo73Iw.png)
For Allow
column, tick the Full control and Modify, and then click OK.
![](https://cdn-images-1.medium.com/max/800/1*mYxLCnsfLel8oDSp7vHXuA.png)
2. Edit the RProfile file
(1) Open R subfolder and find “Rprofile”
(2) Made a copy of “Rprofile” and save it “RprofileBackup”
![](https://cdn-images-1.medium.com/max/800/1*lfhwNVBKs4YEtUkS_Q39tQ.png)
If there is a problem, we can change the file back.
(3) Double click “Rprofile” and open it using any text editor,
(4) Find the following snippet
if(!nzchar(Sys.getenv("R_LIBS_USER")))
Sys.setenv(R_LIBS_USER=
file.path(Sys.getenv("R_USER"), "R",
"win-library",
paste(R.version$major,
sub("\\..*$", "", R.version$minor),
sep=".")
))
Now let’s just delete ‘R_USER’. Now, the above snippet looks as follows:
![](https://cdn-images-1.medium.com/max/800/1*oxSmdB3x2hmPbAnk-xlSFA.png)
We save the change and then close the RGui.
3. Open R and install a package
Now we open the RGui and install a package, for example “ggplot2” by:
install.packages(“ggplot2”)
4. Create personal folder
If it asks you to use a personal library instead, just click yes.
![](https://cdn-images-1.medium.com/max/800/1*POQ4CYgUzdZESYzuUsDTCw.png)
Next, it asks you to create a personal library to install packages into, the easy way is to accept the suggest path by clicking Yes. Then the package will be started to install on your system.
![](https://cdn-images-1.medium.com/max/800/1*omBG3_bEHQ_kYieYBMtl9w.png)
Video version:
If you like the video version of this article, please watch it through the following link. Please subscribe for more tips by click: https://www.youtube.com/channel/UCQpUJn9GfUjKkFP2X-1pjoQ?sub_confirmation=1
More Information:
If you are interested in Python related courses on Python fundamental, Jupyter Notebook, Data Science, Wavelet Transforms, Machine Learning, and so on, welcome you to my online school — Deepsim Academy.