Error in when installing packages in R

HI I am getting below error when I am trying to load/ install any packages. This happened when installed new version of .
Error in nchar(homeDir) : invalid multibyte string, element 1
In addition: Warning message:
In normalizePath(path.expand(path), winslash, mustWork) : path[1]="C:/Users/my.name/OneDrive - companies name/Documents": The system cannot find the path specified

How to solve this issue?

I think your default library has changed with new R installation. Try this--

.libPaths("Path to your libs")

Then after install and load library again

.libPaths("C:/Program Files/R/R-4.2.1")
Error in nchar(homeDir) : invalid multibyte string, element 1

Same error when I try to change path

1 Like

you can try to remove special characters (non-ASCII character) from your homeDir or folder or files and then try again.

This means your home directory contains special character. Can you show a complete console output?

R has problems with cloud-synced folders (OneDrive in your case) and non-ASCII characters in your package library path, I recommend you to set your package library in a non-synced folder.

You can change the default library folder by setting your R_LIBS_SITE environmental variable in a .Reviron or .Rprofile file. For example:

# 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.1.2\\library"

For a more detailed explanation, you can read this blog post

Error in nchar(homeDir) : invalid multibyte string, element 1

Warning message:
In normalizePath(path.expand(path), winslash, mustWork) : path[1]="C:/Users/my.name/OneDrive -(companies name)l/Documents": The system cannot find the path specified

this is the output

look for @andresrcs suggestion. He is right.

R is sensitive and you need to be careful with file and folder names. Don't add "space"/"-" or other special character to your folder or file names that you will use in R. So, change your library folder/ or name then try again.

In simple--

Incorrect way--- "C:/Users/my.name/OneDrive -(companies name)l/Documents" because here == "(companies name)", "-" are special character that creating problem in your case :slight_smile:

correct way--- "C:/Users/my_name/OneDrive_companies name_l/Documents" or
"C:/Users/hhyhfh/Documents"

Thank you for all recos.
My lib paths are

.libPaths()
[1] "C:/Users/my.name/R1"
[2] "C:/Program Files/R/R-4.2.1/library"
Warning message:
In normalizePath(path.expand(path), winslash, mustWork) : path[1]="C:/Users/my.name/OneDrive - companies name/Documents": The system cannot find the path specified

why it still giving me this error? also if I want to remove second lib path what should I do , as second one has space in it so I guess it wont work?

It is strange. Are you running your script in R or Rstudio?

Might be. I think you should uninstalled R and Rstudio completely and try again. May be it will help you :slight_smile:

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.