demo1

This rmarkdown document mixes R and python programming, showing how an object created in R seems immutable when manipulated in python, but a copy made in python can be modified and returned to R with values created in python code.

Create R objects, retrieve in python

Here’s some R code:

x = c(1,2,3)
y = list(c(1,2), 3)

Now in python I prefix with r. to refer to my R values:

r.x
[1.0, 2.0, 3.0]
r.y
[[1.0, 2.0], 3.0]
r.x[1]
2.0
r.y[0]
[1.0, 2.0]

Can’t change passed object, but can modify copy

Change a value in python:

r.y[1] = 7
r.y
[[1.0, 2.0], 3.0]
z = r.y
z[1]
3.0
z[1] = 7.
r.zz = z

In R:

y
[[1]]
[1] 1 2

[[2]]
[1] 3
zz
[[1]]
[1] 1 2

[[2]]
[1] 7