Skip to content Skip to sidebar Skip to footer

SyntaxError %%R In Jupyter

It might be a very simple question (although it seems long). I installed Jupyter today from pip and pip3, so can set kernel as python2 or 3. Then started with an example taken from

Solution 1:

According to the second answer in this post, jupyter no longer allows you to define %%R at the middle or the end of the program. It must be at the very first line.

But if you try putting it in the first line, you won't be able to import pandas as anything typed below the cell will be considered R code. Thus I suggest you use just %R instead of %%R to be on the safer side.

As far as your code is concerned, here is a tweaked version that doesn't give any errors. Also I completely recoded it in R. Turns out due to the rule I mentioned above, you really can't use R cell bodies with Python code anymore.THis code works perfectly as far as the output is concerned:

%%R 
df <- data.frame(Alphabet=c('a', 'b', 'c', 'd','e', 'f', 'g', 'h','i'),
                 A=c(4, 3, 5, 2, 1, 7, 7, 5, 9),
                 B=c(0, 4, 3, 6, 7, 10, 11, 9, 13),
                 C=c(1, 2, 3, 1, 2, 3, 1, 2, 3))
library(ggplot2)
ggplot(data=df, aes(x=A, y=B,color=C)) +
geom_line()+
geom_point()

Post a Comment for "SyntaxError %%R In Jupyter"