Rstudio Notebook编译错误

时间:2014-08-03 18:51:13

标签: r rstudio

我正在研究MAC OS 10.9,R 3.04,Rstudio .98.953。

当我在大多数脚本上运行Compile Notebook时(但不是全部) - 我得到一个解析错误。我正在编译笔记本,点击"编译笔记本" RStudio上的按钮。错误是:

Line 3 Error in parse(text=x, srcfile= src): <text>:21:1 Unexpected '==" 20: 
21: == ^ Calls: <anonymous>... evaluate -> parse_all -> parse_all.character -> execution halted.

虽然我可以编写一些脚本来编译 - 但绝大多数都会得到完全相同的SAME错误。让我觉得它是Mac或Rstudio设置而不是R脚本

我在运行之前已经清除了全局环境(因为这是有人建议的)。

这是一个可重现的脚本,它给了我这个错误(我还有其他几个):

#Social Network Graph
#Attempted Sexual Relations Mad Men TV Show

install.packages("gcookbook")
library(gcookbook) # For the data set
library(igraph)
#look at the data
madmen2

Create a graph object from the data set

g <- graph.data.frame(madmen2, directed=TRUE)
par(mar=c(0,0,0,0))

#first plot
plot(g, layout=layout.fruchterman.reingold, vertex.size=8, edge.arrow.size=0.5,
vertex.label=NA)

library(igraph)
library(gcookbook) # For the data set

Copy madmen and drop every other row

m <- madmen[1:nrow(madmen) %% 2 == 1, ]
g <- graph.data.frame(m, directed=FALSE)

Print out the names of each vertex

V(g)$name

plot(g, layout=layout.fruchterman.reingold, #l.f.r is a popular SN algorythym
vertex.size = 4, # Smaller nodes
vertex.label = V(g)$name, # Set the labels
vertex.label.cex = 0.8, # Slightly smaller font
vertex.label.dist = 0.4, # Offset the labels
vertex.label.color = "black")

change the appearance

g$layout <- layout.fruchterman.reingold #l.f.r is a popular SN algorythym
plot(g)

# View the edges
E(g)

Set some of the labels to "M"

E(g)[c(2,11,19)]$label <- "M"

Set color of all to grey, and then color a few red

E(g)$color <- "grey70"
E(g)[c(2,11,19)]$color <- "red"

plot(g)

1 个答案:

答案 0 :(得分:2)

只要您注释掉正确R代码的行,脚本就会很好地编译。 E.g:

Copy madmen and drop every other row

应该成为:

# Copy madmen and drop every other row