尝试发布一个R笔记本,并不断得到相同的错误(在设计中出错)。url(repos,“源”)试图在不设置镜像的情况下使用CRAN。

时间:2021-07-21 16:49:43

I use OSX Yosemite with XQuartz as was suggested in other questions, and I've been attempting to publish a notebook but get the same error every time. This is what the .R file looks like:

我在其他问题中使用了OSX Yosemite和XQuartz,我一直试图发布一个笔记本,但每次都有相同的错误。这就是。r文件的样子:

#' ---
#' title: "MLB Payroll Analysis"
#' author: "Steven Quartz Universe"
#' date: "21 March 2015"
#' output: pdf_document
#' ---

#loading the payroll data from the Python document
payroll <- read.table("~/Documents/payroll.txt", header=TRUE, quote="\"")

View(payroll)

summary(payroll)

bank <- payroll$PayrollMillions
wins <- payroll$X2014Wins

#loading the payroll data from the Python document
payroll <- read.table("~/Documents/payroll.txt", header=TRUE, quote="\"")

summary(payroll)

bank <- payroll$PayrollMillions
wins <- payroll$X2014Wins

#displaying the mean and sd of payroll and wins (out of 162, of course)
mean(bank)
sd(bank)
mean(wins)
sd(wins)

#setting a linear regression
reg <- lm(wins ~ bank)
summary(reg)
#the regression is valid to significance < .10 (p-value .05072),
#but the R-squared is only .1296, a weak correlation

#a means of comparing the histogram to a normal distribution
histNorm <- function(x, densCol = "darkblue"){
  m <- mean(x)
  std <- sqrt(var(x))
  h <- max(hist(x,plot=FALSE)$density)
  d <- dnorm(x, mean=m, sd=std)
  maxY <- max(h,d)
  hist(x, prob=TRUE,
       xlab="x", ylim=c(0, maxY),
       main="(Probability) Histogram with Normal Density")
  curve(dnorm(x, mean=m, sd=std),
        col=densCol, lwd=2, add=TRUE)
}

#showing the histogram with normal distribution line
histNorm(reg$residuals, "purple")

#QQplots and Shapiro-Wilk test
qqnorm(reg$residuals)
qqline(reg$residuals)
shapiro.test(reg$residuals)
#p-value is .383; this can be considered a normal distribution

plot(reg$fitted.values,reg$residuals)
abline(h = 0)
#variances are wide, but in a channel

install.packages("lmtest")
library(lmtest)
bptest(reg)
#p-value of .849 given; we can assume variances are constant throughout the     distribution

hats <- hatvalues(reg)

hatmu <- mean(hats)
hats[hats > 2 * hatmu]
#we get teams 14 and 19 with high leverage; the Dodgers and Yankees with their     astronomical payrolls

treg <- rstudent(reg)
n <- length(treg)
p <- reg$coefficients
df <- n - p - 1
alpha <- 0.05

#no bonferroni correction for outliers
crit <- qt(1 - alpha/2,df)
treg[abs(treg) > crit]
#no outliers are found

#with bonferroni correction
crit <- qt(1 - (alpha/2)/n,df)
treg[abs(treg) > crit]
#no outliers are found

#comparison of outlier tests
pvals <- pt(-abs(treg),df)*2
padjb <- p.adjust(pvals, method = "bonferroni")
padjf <- p.adjust(pvals, method = "fdr")
cbind(pvals,padjb,padjf)

When I hit Compile Notebook, this is the output:

当我点击编译笔记本时,这是输出:

  |......................                                           |  33%
  ordinary text without R code

  |...........................................                      |  67%
label: unnamed-chunk-1


processing file: payroll.spin.Rmd

Quitting from lines 9-90 (payroll.spin.Rmd) 
Error in contrib.url(repos, "source") : 
  trying to use CRAN without setting a mirror
Calls: <Anonymous> ... withVisible -> eval -> eval -> install.packages ->     contrib.url

I've looked through other questions on how to rectify this, but to no avail. I've done the command line fixes, again to no avail. Could someone point me as to what I'm doing wrong? Thanks kindly.

我已经研究过其他关于如何纠正这个问题的问题,但都无济于事。我已经完成了命令行修复,同样没有效果。有人能指出我做错了什么吗?谢谢你亲切的。

4 个解决方案

#1


11  

The line

这条线

install.packages("lmtest")

is the problem here. As is hinted by the error message

是这里的问题。正如错误消息所暗示的那样。

Error in contrib.url(repos, "source") : 
  trying to use CRAN without setting a mirror

it is expected that you provide a link to a repo for the package. So changing it to (for instance):

预计您将为该包提供一个链接到repo。所以把它改成(例如):

install.packages("lmtest", repos = "http://cran.us.r-project.org")

should do the trick. But as MrFlick and Ben Bolkers pointed out in their comments, it should probably be done when the package is not already installed.

应该足够了。但是,正如MrFlick和Ben Bolkers在评论中指出的那样,当包装还没有安装时,很可能就会这样做。

#2


3  

I had this same issue with a Knit HTML publish, i modified the very beginning of the file like so:

我有一个同样的问题,我用一个编织的HTML发布,我修改了文件的开头,像这样:

---
title: "dialectic"
author: "micah smith"
date: "3/4/2017"
output: html_document
---

```{r setup, include=FALSE}
chooseCRANmirror(graphics=FALSE, ind=1)
knitr::opts_chunk$set(echo = TRUE)

the chooseCRANmirror(graphics=FALSE, ind=1) was the line that fixed it

该选择镜像(图形=FALSE, ind=1)是修复它的行。

#3


2  

chooseCRANmirror(graphics=FALSE, ind=1)
knitr::opts_chunk$set(echo = TRUE)

Write this at the start of your chunk if you have already installed the package.

如果您已经安装了这个包,那么在块的开始处写这个。

#4


0  

If you have already run your install.packages("___") script, then you can try to set that codechunk to eval = FALSE when you try to knit your markdown file?

如果您已经运行了您的安装。软件包(“___”)脚本,那么您可以尝试将该代码块设置为eval = FALSE,当您尝试编织您的markdown文件时?

#1


11  

The line

这条线

install.packages("lmtest")

is the problem here. As is hinted by the error message

是这里的问题。正如错误消息所暗示的那样。

Error in contrib.url(repos, "source") : 
  trying to use CRAN without setting a mirror

it is expected that you provide a link to a repo for the package. So changing it to (for instance):

预计您将为该包提供一个链接到repo。所以把它改成(例如):

install.packages("lmtest", repos = "http://cran.us.r-project.org")

should do the trick. But as MrFlick and Ben Bolkers pointed out in their comments, it should probably be done when the package is not already installed.

应该足够了。但是,正如MrFlick和Ben Bolkers在评论中指出的那样,当包装还没有安装时,很可能就会这样做。

#2


3  

I had this same issue with a Knit HTML publish, i modified the very beginning of the file like so:

我有一个同样的问题,我用一个编织的HTML发布,我修改了文件的开头,像这样:

---
title: "dialectic"
author: "micah smith"
date: "3/4/2017"
output: html_document
---

```{r setup, include=FALSE}
chooseCRANmirror(graphics=FALSE, ind=1)
knitr::opts_chunk$set(echo = TRUE)

the chooseCRANmirror(graphics=FALSE, ind=1) was the line that fixed it

该选择镜像(图形=FALSE, ind=1)是修复它的行。

#3


2  

chooseCRANmirror(graphics=FALSE, ind=1)
knitr::opts_chunk$set(echo = TRUE)

Write this at the start of your chunk if you have already installed the package.

如果您已经安装了这个包,那么在块的开始处写这个。

#4


0  

If you have already run your install.packages("___") script, then you can try to set that codechunk to eval = FALSE when you try to knit your markdown file?

如果您已经运行了您的安装。软件包(“___”)脚本,那么您可以尝试将该代码块设置为eval = FALSE,当您尝试编织您的markdown文件时?