rstudioapi: Safely Access the RStudio API

> library(rstudioapi)

バージョン: 0.6


関数名 概略
askForPassword Ask the user for a password interactively
callFun Call an RStudio API function
document_position Create a Document Position
document_range Create a Range
editor-information Retrieve Information about an RStudio Editor
getActiveProject Path to Active RStudio Project
getVersion Return the current version of the RStudio API
hasFun Exists/get for RStudio functions
insertText Modify the Contents of a Document
isAvailable Check if RStudio is running.
navigateToFile Navigate to File
previewRd Preview an Rd topic in the Help pane
primary_selection Extract the Primary Selection
sendToConsole Send Code to the R Console
sourceMarkers Display Source Markers
versionInfo RStudio Version Information
viewer View local web content within RStudio

askForPassword

パスワード入力を求めるウィンドウを起動

> rstudioapi::askForPassword("パスワードを入力してください")

callFun

関数の呼び出し

> callFun(fname = "versionInfo")
$citation

To cite RStudio in publications use:

  RStudio Team (2016). RStudio: Integrated Development for R.
  RStudio, Inc., Boston, MA URL http://www.rstudio.com/.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {RStudio: Integrated Development Environment for R},
    author = {{RStudio Team}},
    organization = {RStudio, Inc.},
    address = {Boston, MA},
    year = {2016},
    url = {http://www.rstudio.com/},
  }


$mode
[1] "desktop"

$version
[1] '1.1.96'

getActiveDocumentContext

> getActiveDocumentContext()
Document Context: 
- id:        '28D2A377'
- path:      '~/git/rpkg_showcase/README.Rmd'
- contents:  <35 rows>
Document Selection:
- [29, 1] -- [29, 1]: ''

getActiveProject

> getActiveProject()
[1] "/Users/uri/git/rpkg_showcase"

getVersion

使用中のRStudioのバージョンを表示する

> getVersion()
[1] '1.1.96'

insertText

コンソールやソースコードに処理を加える

> # コメントとしてHelloを出力
> insertText(text = "# Hello\n")

指定されたファイルを開く

> navigateToFile(file = "README.md")

sendToConsole

R関数・コードの実行

Arguments

  • code
  • execute
> rstudioapi::sendToConsole(".Platform; print('hello')", execute = TRUE)

sourceMarkers

Arguments

  • name
  • markers
  • basePath
  • autoSelect
> sourceMarkers(name, markers, basePath = NULL, autoSelect = c("none", "first", "error"))

versionInfo

RStudioに関する情報

> versionInfo()
$citation

To cite RStudio in publications use:

  RStudio Team (2016). RStudio: Integrated Development for R.
  RStudio, Inc., Boston, MA URL http://www.rstudio.com/.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {RStudio: Integrated Development Environment for R},
    author = {{RStudio Team}},
    organization = {RStudio, Inc.},
    address = {Boston, MA},
    year = {2016},
    url = {http://www.rstudio.com/},
  }


$mode
[1] "desktop"

$version
[1] '1.1.96'

viewer

RStudioのviewerパネルにウェブサイトを表示する

Arguments

  • url
  • height
> rstudioapi::viewer("http://localhost:8100")