问题描述
我对整个R编程非常陌生,并尝试遵循本教程,其中model1
函数用于查找三个变量之间的Andrew F. Hayes相关性.如本教程中所述,我已经安装了软件包:
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")
install.packages("devtools")
install.packages("processR")
devtools::install_github("markhwhiteii/processr")
我还遵循了以下步骤:
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)
我收到错误消息:
并运行
mod1result <- processr::model1(iv = "var1", dv = "var2", mod = "cond", data = df3)
奇怪的是,相同的代码昨天才起作用,而现在却不起作用.如果您能帮助我了解问题所在以及如何解决,我将不胜感激.
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.我不确定.libPaths()
是什么,但是由于某些原因,它会在我的mac机上返回两个路径:
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
/usr/local/lib/R/3.6/site-library
/usr/local/Cellar/r/3.6.2/lib/R/library
这是否意味着我有两个R安装,这是导致上述问题的主要原因吗?
does it mean that I have two installations of R and this is the main cause of the above issues?
P.S.2.确定.这似乎是Jupyter的错,因为终端中的一切工作都很好.
P.S.2. OK. This seems to be Jupyter's fault as everything is just working fine in the terminal.
P.S.3..似乎在终端上起作用的是:
P.S.3. What seems to be working in the terminal is:
-
sudo r
-
devtools::install_github("markhwhiteii/processr")
-
library(processr)
注意processr
中的小写字母
r
sudo r
devtools::install_github("markhwhiteii/processr")
library(processr)
notice lower caser
in theprocessr
P.S.4..我不确定这是否是Jupyter的错.
P.S.4. I'm not sure if this is Jupyter's fault.
P.S.5..我也尝试在Windows上安装软件包.更糟的是.我无法解决问题:
P.S.5. I tried installing the packages on Windows as well. It was even worse. I can't get passed the issue:
我认为解决这个问题的关键可能是了解这些软件包之间的区别:
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")
install.packages("processR")
devtools::install_github("markhwhiteii/processr")
devtools::install_github("cardiomoon/processR")
推荐答案
好的,经过几个小时的反复试验,我认为我的解决方法比较麻烦,但不是解决方案!
OK, after a couple of hours of trial and error, I think I have a messy workaround, not a solution though!
- 在一个终端中运行
sudo r
- 在另一个目录中运行
jupyter notebook
并打开一个R笔记本(我想您已经安装了内核) -
现在您应该了解
devtools::install_github("markhwhiteii/processr")
和install.packages("processR")
是两个不同的软件包,并且每次在Jupyter Notebook中重新启动内核时都进行了安装
- 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 Notebook
先在R终端中安装devtools::install_github("markhwhiteii/processr")
基本上,您同时需要processr
和processR
!
Basically you need both processr
and processR
!
顺便说一句,同样的问题是R终端.您必须以sudo
运行,并按照上述步骤操作,一切正常!
BTW, the same issue is the R terminal. You have to run as sudo
and follow the above steps to get everything working!
这篇关于无法在Jupyter Notebook中加载processR包的`model1`函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!