mpg
mpg

Reputation: 3919

Rstudio Notebook compile errors

I am working on MAC OS 10.9, R 3.04, Rstudio .98.953.

When I run Compile Notebook on most of my scripts (but not all)- I get a parse error. I am compiling the notebook by clicking the "compile notebook" button on RStudio. The error is:

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.

While I can get a few scripts to compile- that vast majority I get the exact SAME error. Makes me think it is a Mac or Rstudio setting instead of the R script(s)

I have cleared the global environment prior to running (as this is something someone suggested).

Here is a reproducible script that gives me this error (I have several others):

#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)

Upvotes: 0

Views: 1976

Answers (1)

Alexander Radev
Alexander Radev

Reputation: 662

The script actually compiles quite well as soon as you comment out the lines that are NOT proper R code. E.g.:

Copy madmen and drop every other row

Should become:

# Copy madmen and drop every other row

Upvotes: 2

Related Questions