- Learning Jupyter 5
- Dan Toomey
- 477字
- 2021-08-13 15:42:12
Basic R in Jupyter
Start a new R Notebook and call it R Basics. We can enter a small script just so we can see how the steps progress for R script. Enter the following into separate cells of your Notebook:
myString <- "Hello, World!"
print (myString)
From here, you will end up with a starting screen that looks like this:

We should note the aspects of the R Notebook view:
- We have the R logo in the upper-right corner. You will see this logo running in other R installations.
- There is also the peculiar R O just below the R icon. If the O unfilled circle displays, the unfilled circle indicates that the kernel is at rest, and the filled circle indicates that the kernel is working.
- The rest of the menu items are the same as the ones we saw previously.
This is a very simple script–set a variable in one cell and then print out its value in another cell. Once executed (Cell | Run All), you will see your results:

So, just as if you run the script in an R interpreter, you get your output (with the numerical prefix). Jupyter has counted the statements so that we have incremental numbering of the cells. Jupyter has not done anything special to print out variables for debugging; you will have to do that separately.
If we look at the R server-logging statements (a command-line window was created when we started Jupyter), we will be able to see the actions that took place:
$ jupyter notebook [I 11:00:06.965 NotebookApp] Serving notebooks from local directory: /Users/dtoomey/miniconda3/bin [I 11:00:06.965 NotebookApp] 0 active kernels [I 11:00:06.965 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/ [I 11:00:06.965 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [I 11:00:17.447 NotebookApp] Creating new notebook in [I 11:00:18.199 NotebookApp] Kernel started: 518308da-460a-4eb9-9959-1411e31dec69 [1] "Got unhandled msg_type:" "comm_open" [I 11:02:18.160 NotebookApp] Saving file at /Untitled.ipynb [I 11:08:27.340 NotebookApp] Saving file at /R Basics.ipynb [1] "Got unhandled msg_type:" "comm_open" [I 11:14:45.204 NotebookApp] Saving file at /R Basics.ipynb
We started the server, created a new Notebook, and saved it as R Basics. If we open the IPYNB file on disk (using a text editor), we will be able to see the following:
{ "cells": [ ...<similar to previously displayed> ], "metadata": { "kernelspec": { "display_name": "R", "language": "R", "name": "ir" }, "language_info": { "codemirror_mode": "r", "file_extension": ".r", "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", "version": "3.4.3" } }, ...<omitted> }
This is a little different than what we saw in the prior chapter on Python Notebook coding. In particular, the metadata clearly targets the script cells to be R script. Note that the actual cells are not specific to a language – they are just scripts that will be executed as per the metadata directives.
- 大數據管理系統
- Design for the Future
- 腦動力:C語言函數速查效率手冊
- Seven NoSQL Databases in a Week
- 影視后期制作(Avid Media Composer 5.0)
- ROS機器人編程與SLAM算法解析指南
- 嵌入式Linux上的C語言編程實踐
- Python Algorithmic Trading Cookbook
- 21天學通Visual Basic
- Visual C++編程全能詞典
- Windows Server 2008 R2活動目錄內幕
- 大數據導論
- Oracle 11g Anti-hacker's Cookbook
- 計算機硬件技術基礎(第2版)
- 天才與算法:人腦與AI的數學思維