问题
I am very new to the whole R programming and trying to follow this tutorial, where the model1
function is used to find the Andrew F. Hayes correlation between three variables. As indicated in the tutorial I have the packages installed:
install.packages("devtools")
install.packages("processR")
devtools::install_github("markhwhiteii/processr")
I have also followed the steps:
set.seed(1839)
var1 <- rnorm(100)
cond <- rbinom(100, 1, .5)
var2 <- var1 * cond + rnorm(100)
df3 <- data.frame(var1, var2, cond)
head(df3)
accordingly. However, when running:
mod1result <- model1(iv = "var1", dv = "var2", mod = "cond", data = df3)
I get the error message:
Error in model1(iv = "var1", dv = "var2", mod = "cond", data = df3): could not find function "model1" Traceback:
and running
mod1result <- processr::model1(iv = "var1", dv = "var2", mod = "cond", data = df3)
Error in loadNamespace(name): there is no package called ‘processr’ Traceback:
The strange thing is that the same code just worked yesterday and now it doesn't. I would appreciate it if you could help me understand what is wrong and how I can resolve it.
P.S.1. I'm not sure what .libPaths()
is but for some reason it returns two paths on my mac:
/usr/local/lib/R/3.6/site-library
/usr/local/Cellar/r/3.6.2/lib/R/library
does it mean that I have two installations of R and this is the main cause of the above issues?
P.S.2. OK. This seems to be Jupyter's fault as everything is just working fine in the terminal.
P.S.3. What seems to be working in the terminal is:
sudo r
devtools::install_github("markhwhiteii/processr")
library(processr)
notice lower caser
in theprocessr
P.S.4. I'm not sure if this is Jupyter's fault.
P.S.5. I tried installing the packages on Windows as well. It was even worse. I can't get passed the issue:
Error: Failed to install 'processr' from GitHub: (converted from warning) cannot remove the prior installation of package ‘digest’
I think maybe the key to solving this problem is to understand what is the difference between these packages:
install.packages("processR")
devtools::install_github("markhwhiteii/processr")
devtools::install_github("cardiomoon/processR")
回答1:
OK, after a couple of hours of trial and error, I think I have a messy workaround, not a solution though!
- run
sudo r
in one terminal - run
jupyter notebook
in another and open an R notebook (I suppose you have the kernel installed) now you should understand that the
devtools::install_github("markhwhiteii/processr")
andinstall.packages("processR")
are two different packages and you gave install both every time you restart your kernel in the Jupyter Notebookinstall
devtools::install_github("markhwhiteii/processr")
first in the R terminal- now in the Jupyter side you should be able to
library(processr)
and runprocessr::model1
- next install the
install.packages("processR")
on the R terminal - now import the
library(processR)
- now you should be able to run the functions such as
pmacroModel
etc
Basically you need both processr
and processR
!
BTW, the same issue is the R terminal. You have to run as sudo
and follow the above steps to get everything working!
回答2:
From the tutorial page you references, install processr
(not processR
) in the following way:
# Run this if devtools isn't installed.
# install.packages("devtools")
# Run to install "processr"
devtools::install_github("markhwhiteii/processr")
After that successfully completes, processr::model1
will be defined.
When running the code in this post it produces a result:
set.seed(1839)
var1 <- rnorm(100)
cond <- rbinom(100, 1, .5)
var2 <- var1 * cond + rnorm(100)
df3 <- data.frame(var1, var2, cond)
head(df3)
mod1result <- processr::model1(iv = "var1", dv = "var2", mod = "cond", data = df3)
mod1result
## # A tibble: 6 x 5
## term estimate std.error statistic p.value
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 intercept 0.133 0.146 0.916 0.362
## 2 var1 0.0696 0.156 0.445 0.657
## 3 cond -0.173 0.200 -0.865 0.389
## 4 interaction 0.854 0.213 4.01 0.000118
## 5 when cond = 0 0.0696 0.156 0.445 0.657
## 6 when cond = 1 0.924 0.144 6.40 0.00000000577
来源:https://stackoverflow.com/questions/60291182/can-not-load-the-model1-function-of-the-processr-package-in-a-jupyter-notebook