BEGIN.Python: Execute Python interactively from within R

Description Usage Details Value Note Examples

View source: R/PySource.R

Description

The function BEGIN.Python starts an Python read-eval-print loop.

Usage

1

Details

BEGIN.Python emulates the behavior of the Python terminal and therefore allows interactive Python code development from within R.

Value

Returns the entered code as character, code lines which throw an exception are omitted.

Note

The function BEGIN.Python relies on reading from the stdin therefore this function wont work with RStudio because of a known RStudio issue.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
code <-
BEGIN.Python()
import os
os.getcwd()
dir(os)
x = 3**3
for i in xrange(10):
    if (i > 5):
        print(i)

END.Python
## NOTE: BEGIN.Python returns the successfully executed code as character.
cat(code, sep="\n")
pyGet0("x")

## End(Not run)

PythonInR documentation built on May 2, 2019, 5:17 p.m.