试图发布一个R笔记本并继续得到相同的错误(contrib.url中的错误(repos," source")尝试使用CRAN而不设置镜像

时间:2015-03-22 00:31:14

标签: r rstudio

我在其他问题中使用了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)

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

  |......................                                           |  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

我已经查看了有关如何纠正这个问题的其他问题,但无济于事。我已完成命令行修复,再次无济于事。有人能指出我做错了什么吗?谢天谢地。

5 个答案:

答案 0 :(得分:17)

该行

install.packages("lmtest")

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

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

预计您提供指向包的仓库的链接。所以改成它(例如):

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

应该做的伎俩。但正如MrFlick和Ben Bolkers在评论中指出的那样,应该在尚未安装软件包时完成。

答案 1 :(得分:7)

我遇到了与Knit 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)

chooseCRANmirror(graphics=FALSE, ind=1)是修复它的行

答案 2 :(得分:3)

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

如果您已经安装了软件包,请将其写在块的开头。

答案 3 :(得分:1)

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

答案 4 :(得分:0)

如果要通过pkgs <- c("moments", "ggplot2", "dplyr", "tidyr", "tidyverse") install.packages(pkgs, repos = "http://cran.us.r-project.org") 变量安装多个软件包,请执行此操作。它为我工作。在修复它之前,我无法编辑pdf。

java.lang.IllegalStateException: No constructor class org.eclipse.jetty.server.ServerConnector([],{}) in file:/C:/Users/sanja/Downloads/geoserver-2.17.1-bin/etc/jetty-https.xml
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:406)
        at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:311)
        at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1558)
        at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1512)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1511)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:220)
        at org.eclipse.jetty.start.Main.start(Main.java:490)
        at org.eclipse.jetty.start.Main.main(Main.java:77)
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:220)
        at org.eclipse.jetty.start.Main.start(Main.java:490)
        at org.eclipse.jetty.start.Main.main(Main.java:77)
Caused by: java.lang.IllegalStateException: No constructor class org.eclipse.jetty.server.ServerConnector([],{}) in file:/C:/Users/sanja/Downloads/geoserver-2.17.1-bin/etc/jetty-https.xml
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:406)
        at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:311)
        at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1558)
        at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1512)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1511)
        ... 7 more
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:220)
        at org.eclipse.jetty.start.Main.start(Main.java:490)
        at org.eclipse.jetty.start.Main.main(Main.java:77)
Caused by: java.lang.IllegalStateException: No constructor class org.eclipse.jetty.server.ServerConnector([],{}) in file:/C:/Users/sanja/Downloads/geoserver-2.17.1-bin/etc/jetty-https.xml
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:406)
        at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:311)
        at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1558)
        at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1512)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1511)
        ... 7 more