0

I am trying to use retriculate to run python code from R. This works, for example I can run:

library(retriculate)
py_run_file("mypyfile.py")

where the mypyfile.py contains:

import pandas as pd
df = pd.DataFrame({a:[1,2], b:[3,4]})
df.to_csv(mypythongenerateddata.csv)

to keep things easier I would prefer to just place these three lines of python code in the R script directly, as opposed to sourcing the python script. The documentation seems to suggest using a markdownfile, which I am not to fond off. enter link description here

1 Answer 1

1

You could use py_run_string:

library(reticulate)

py_run_string("
import pandas as pd
df = pd.DataFrame({'a':[1,2], 'b':[3,4]})
df.to_csv('mypythongenerateddata.csv')")

py$df
#>   a b
#> 1 1 3
#> 2 2 4
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.