Skip to main content
3 of 4
added 34 characters in body
Mike Honeychurch
  • 37.8k
  • 3
  • 87
  • 161

The following is a style for an R cell, inspired by this answer. You can add this to your stylesheet (change the styles to your liking):

Cell[StyleData["R"],
    CellMargins->{{66, 10}, {5, 10}},
    Evaluatable->True,
    Background->RGBColor[1,1,0.85],
    AutoQuoteCharacters->{},
    CellEvaluationFunction -> (REvaluate["{"<>ToString@#<>"}"]&),
    CellFrameLabels -> {{None,"R"},{None,None}},
    LanguageCategory->"R",
    FormatType->InputForm,
    FontFamily -> "Inconsolata-dz",
    MenuCommandKey->"8"
]

You can now create a new R cell by pressing Cmd8, but you'll have to manually remove the MenuCommandKey setting from the "Code" style before it'll work. Alternately, you can simply press Cmd0 and choose R from the list.

You then use it just like any other input/code cell. Paste your R code into the cell and hit ShiftReturn and it'll evaluate it (assuming RLink has already been called, etc.)

enter image description here

rm -rf
  • 89.3k
  • 21
  • 297
  • 480