Need help to get Rstudio running for the first time, packages won't install

Hello everyone,

I am a first time R user in dire need of some help.
I have tried to get started with R and Rstudio for a few days now, but something seems to be wrong. Namely, I can't seem to be able to install any packages, at least they won't show up in the packages pane.
When I open Rstudio, I receive 2 reoccurring messages in the console:

Error in nchar(homeDir) : invalid multibyte string, element 1
In addition: Warning message:
In normalizePath(path.expand(path), winslash, mustWork) : path[1]="C:/Users/Lenovo/OneDrive HNEE/OneDrive - Hochschule f�r nachhaltige Entwicklung Eberswalde/Documents": The system cannot find the path specified

From researching my problem, I understand that Rstudio has trouble with both non-ASCII characters and OneDrive-synced folders. The folder in question would have a "ü" in the file path (where the "?" is), which I can not change due to it being the name of my university, and it is just the name of the OneDrive folder by default.

In order to circumvent this, I have completely unsynced and even uninstalled OneDrive from my computer, but the message still keeps showing up.

I have also tried to set the home directory and library location to a non-synced folder on my desktop, which has only ASCII-characters in its location.
I have tried that via the Globel Settings in Rstudio, by editing the Rprofile.site file and by creating an .Rprofile file in the base of my home directory, since one did not appear on its own.

In the last two, I added the following command:

.First <- function(){
.libPaths(c("C:/Users/Lenovo/Desktop/NonSyncedFolder/R_HOME/library"))
}

All to no avail. I still get the previously mentioned Error and Warning messages and can not seem to install any packages.

I really am at my wits' end here and any help would be much appreciated.

See this recent post for the setting to change the default directory,

As detailed in my post, this didn't work.

It changed the directory to the new folder,
At least it shows up in the "files" pane,
but the error persists

You did this?

# In a .Renviron file you can set it by adding a line like this one with the desired location 
R_LIBS_SITE="C:\\Program Files\\R\\R-4.2.1\\library"

Yes, I created a .txt file called ".Renviron" in the base of my home directory and added the line provided, changing the folder location to a Non-Cloud-Synced folder with only ASCII characters in its path. Same error, same warning.

It looks to me that your Onedrive folder is being defined as the R_USER directory (perhaps because Onedrive is defined as your windows HOME directory?).

Probably the easiest way to solve this is by setting an environment variable:

  1. Open the Start Menu and type "Environment variable" (German: "Umgebungsvariablen").
  2. Click to open "Edit environment variables for your account" (German: "Umgebungsvariablen für dieses Konto bearbeiten")
  3. Under the top box, click New ("Neu") and enter "R_HOME" as the name and "c:/Users/Lenovo/Documents" as the value.
  4. Restart RStudio

It makes little sense to sync the R_HOME with Onedrive anyway, so this setting is sensible in any event.

It shouldn't be a problem to put your projects under the Onedrive path. If you do have problems, map your Onedrive folder to a letter (from explorer: Start > Einfacher Zugriff) and open your RStudio project from the mapped directory. That way, R doesn't see the special characters.

1 Like

That didn't work either, I am still getting the same error when I open the packages pane or try to install any

In case anyone is interested, I ended up fixing the issue by resetting windows on my pc to factory settings and then reinstalling R ans RStudio, but not OneDrive.

This topic was automatically closed 7 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.