Effective Way to Solve the Path Problem of R installing Packages on Windows

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:


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.

Select Security, and then click User (DESKTOP JRUIS9V\User) followed by clicking Edit.

For Allow column, tick the Full control and Modify, and then click OK.

2. Edit the RProfile file

(1) Open R subfolder and find “Rprofile”

(2) Made a copy of “Rprofile” and save it “RprofileBackup”

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

                 file.path(Sys.getenv("R_USER"), "R",
                                      sub("\\..*$", "",  

Now let’s just delete ‘R_USER’. Now, the above snippet looks as follows:

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:


4. Create personal folder

If it asks you to use a personal library instead, just click yes.

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.

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.

ClosePlease login
0 - 0

Thank You For Your Vote!

Sorry You have Already Voted!

Please follow and like me:

Leave a Reply

Your email address will not be published. Required fields are marked *