Unable to install new packages or use preinstalled packages after installing Rtools40

Hi everyone, I am new in R. I was running DESeq2 tool for Differentially expression analysis in R version 3, OS: Windows 10. As per requirement by one of the script for my data analysis I installed Rtools40 without realizing it was made for R version 4. So, after installing Rtools4 I neither could intall new packages nor use preinstalled packages(in this case, DESeq2 tool from BiocManager package). The error I got:

Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Program Files/R/R-4.0.2/library/stats/libs/x64/stats.dll':
LoadLibrary failure: The specified module could not be found.

So I unstalled Rtools40 as I thought Rtools40 is the reason for getting the above error. But this didn't work. So I uninstalled the R version 3 and installed R version 4 and Rtools40. This didn't working either. Now, I am unable run anything in R for my analysis as the needed packages are not available in the library. Whenever I try to install the DESeq2 tool from BiocManager I kept getting error:
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Program Files/R/R-4.0.2/library/stats/libs/x64/stats.dll':
LoadLibrary failure: The specified module could not be found.

I would also like to add that I successfully created the text file ./Renviron while installing Rtools40 both the times but as it is a hidden file I couldn't locate it on my device even I failed to locate it in Library documents.

Please help me dealing with this error as I really want my R and R packages back for my work.

Thank you for your time.


I think this post might help

It has to do with the PATH environment variable.

Hope this helps,

Hi, I added the PATH in the window's settings:

  1. searched for environmental variables
  2. selected edit environment variables for your account
  3. clicked "new" and added name and path there. Then pressed "OK". (for me the PATH is "C:\rtools40\usr\bin\make.exe")

The another way added PATH is in R using:

writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")

But none of these helped as it still give me error while installing package.


Sorry to hear it didn't work. I'm not very familiar with this, but I'll attach @Yarnabrina to this post as he provided a solution to similar issues in the related post and is a sustainer here as well. If he can't help you (or does't respond within a few days) let me know and I'll ask the RStudio team to help you out.


Hi, Thank you so much for your help, really appreciate it.

I just a posted the solution there because it worked, but I'm not at all any expert. Andres seems to be far more knowledgable regarding various system configuration related issues.

Since I'm here, the only thing I can say is there is probably no need to add it to PATH via GUI, and also to ~/.Renviron. I'm not sure whether any conflict will occur or not, but why take the risk?

Since your error indicates that something is wrong stats, I'll suggest to uninstall both R and Rtools, and clear the remaining files from Program Files manually, if any. Also, if not a large size, you can consider to delete your personal library as well. By the way, Windows provide the option to see hidden files. See here.

After cleaning, restart you system, and install R 4.0.2 and Rtools40. Then either add to PATH using GUI (what i did, as I'm not a command prompt person), or using that command you used (also suggested in official documentation). After that, see whether you're successful or not directly from R GUI. If prompted, accept separate personal library, to avoid corrupting base R packages.

If all these fail, my limited knowledge is depleted and I'll hope that someone else will help you in this issue. A lot of people seem to have problems with R >=4.0.0, so I must have been terribly lucky.

Anyway, best of luck!

Yes, I meant that. And the environment file has a . before it I think, not just Renviron.

@kmmistr1, it's ~/.Renviron. See your own post:

. before / means current working directory, while ~ is the home directory, and . ina a file name usually makes it hidden. They are not same.

Thanks @Yarnabrina, for the solution. I already tried once by uninstalling R and Rtools. and reinstalled them again. I also tried to look for the hidden file ~/Renviron (which I remember I successfully created it) to delete it but I couldn't find it even after un hiding all the files and folder. But I will give it a go again. Hopefully it will work this time. And sorry for getting back to you so late.

Note: When I installed Rtools for the first time I was using R version 3 without realising Rtools is made for version 4. After that I uninstalled R version 3 and Rtools both and installed version 4 and Rtools again.


Hi @Yarnabrina, one question I would like to ask you, in your message you suuggessted me to delete my personal library, by personal library you mean "C:\Users\krishna\R\win-library\4.0" where all my R packages for version 4 are stored?


@Yarnabrina yes its ./Renviron, thanks.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.