In R-4.2.0 on windows, package 'stats' in options("defaultPackages") was not found.
See original GitHub issueUsing R version 4.2.0 on Windows, this prior issue with loading stats.dll
https://github.com/rdotnet/rdotnet/issues/127 seems to have resurfaced.
Here, I show that rnorm
works with R 4.0.2 but fails with R 4.2.0.
Works with old R version 4.0.2
#r "nuget: R.NET"
open RDotNet
REngine.SetEnvironmentVariables("c:/program files/r/r-4.0.2/bin/x64", "c:/program files/r/r-4.0.2")
let engine = REngine.GetInstance()
engine.Evaluate("set.seed(1);rnorm(1)").AsNumeric()
// val it: NumericVector = seq [-0.6264538107]
Fails with R version 4.2.0
#r "nuget: R.NET"
open RDotNet
REngine.SetEnvironmentVariables("c:/program files/r/r-4.2.0/bin/x64", "c:/program files/r/r-4.2.0")
let engine = REngine.GetInstance()
(*
During startup - Warning message:
package 'stats' in options("defaultPackages") was not found
val engine: REngine
*)
engine.Evaluate("set.seed(1);rnorm(1)").AsNumeric()
(*
Error in rnorm(1) : could not find function "rnorm"
In addition: Warning message:
'memory.limit()' is no longer supported
RDotNet.EvaluationException: Error in rnorm(1) : could not find function "rnorm"
at RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement, REnvironment environment)
at RDotNet.REngine.Defer(String statement, REnvironment environment)+MoveNext()
at System.Linq.Enumerable.TryGetLast[TSource](IEnumerable`1 source, Boolean& found)
at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
at RDotNet.REngine.Evaluate(String statement, REnvironment environment)
at <StartupCode$FSI_0005>.$FSI_0005.main@()
Stopped due to error
*)
> engine.Evaluate("library(stats)").AsCharacter()
(*
Error: package or namespace load failed for 'stats' in inDL(x, as.logical(local), as.logical(now), ...):
unable to load shared object 'C:/Program Files/R/R-4.2.0/library/stats/libs/x64/stats.dll':
LoadLibrary failure: The specified module could not be found.
RDotNet.EvaluationException: Error: package or namespace load failed for 'stats' in inDL(x, as.logical(local), as.logical(now), ...):
unable to load shared object 'C:/Program Files/R/R-4.2.0/library/stats/libs/x64/stats.dll':
LoadLibrary failure: The specified module could not be found.
at RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement, REnvironment environment)
at RDotNet.REngine.Defer(String statement, REnvironment environment)+MoveNext()
at System.Linq.Enumerable.TryGetLast[TSource](IEnumerable`1 source, Boolean& found)
at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
at RDotNet.REngine.Evaluate(String statement, REnvironment environment)
at <StartupCode$FSI_0006>.$FSI_0006.main@()
Stopped due to error
*)
Issue Analytics
- State:
- Created a year ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
Stat package will not load after installing RTools - General
Unable to load shared object on startup in RStudio only (R4.0.0 / RStudio ... Warning message: package 'stats' in options("defaultPackages") was not found...
Read more >package 'stats' in options("defaultPackages") was not found ...
Go to the package window and see if the stats is checked or not. If it's not checked, check it and install/or update...
Read more >R Installation and Administration
Replacing the case-changing functions was new in R 4.1.0 and the default on macOS (and on Windows since R 4.2.0). Replacement of the...
Read more >R Broken Even after Reinstall : r/rstats
I am using newest version of r and rStudio on windows. Error: package or ... package 'stats' in options("defaultPackages") was not found.
Read more >R Installation and Administration - 6 Add-on packages
R CMD INSTALL works in Windows to install source packages. No additional tools are needed if the package does not contain compiled code,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Workarounds that are available:
C:\Program Files\R\R-4.2.0\bin\x64
to thePATH
environment variable using the standard Windows System Properties > Environment VariablesC:\Program Files\R\R-4.2.0\library\base\R\Rprofile
(per earlier comment)engine.Evaluate("Sys.setenv(PATH = paste(\"C:/Program Files/R/R-4.2.0/bin/x64\", Sys.getenv(\"PATH\"), sep=\";\"))");
after initializing REngine (per earlier comment)Awesome find @nhirschey!!! Thanks so much. rdotnet doesn’t itself explicitly call
Rcmd_environ
. I tried editing that file to update thePATH
, and it didn’t appear to pick up my changed path. Even going so far as to remove that file entirely didn’t seem to make a difference for when rdotnet runs. I think that is only used forR CMD
invocation.But along those lines, I think the
PATH
changes are being made inC:\Program Files\R\R-4.2.0\library\base\R\Rprofile
. At the bottom of that file, there is code to update the path with RTools. I can also edit it as such and have it work: