New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run custom function with input #315

Open
rb643 opened this Issue Jul 15, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@rb643

rb643 commented Jul 15, 2018

Is it possible to use reticulate to run custom python script that require user input directly from R?

say I have a function called plotcustomgraph.py that requires a csv file as input and writes out a pdf, is it somehow possible to call this function from within R using reticulate?

@jjallaire

This comment has been minimized.

Show comment
Hide comment
@jjallaire

jjallaire Jul 15, 2018

Member

If Python is asking for user input it's likely using standard tty mechanisms which generally won't work from R. Here I think you want to ask the user's input within R then pass those inputs to the Python code (e.g. as function arguments).

Member

jjallaire commented Jul 15, 2018

If Python is asking for user input it's likely using standard tty mechanisms which generally won't work from R. Here I think you want to ask the user's input within R then pass those inputs to the Python code (e.g. as function arguments).

@rb643

This comment has been minimized.

Show comment
Hide comment
@rb643

rb643 Jul 15, 2018

So would that look something like this?

py_run_file('plotcustomgraph.py', file.csv)

rb643 commented Jul 15, 2018

So would that look something like this?

py_run_file('plotcustomgraph.py', file.csv)

@jjallaire

This comment has been minimized.

Show comment
Hide comment
@jjallaire

jjallaire Jul 15, 2018

Member

No, you would write a Python function, source the script containing the function, then call the function from R. See https://rstudio.github.io/reticulate/articles/calling_python.html#sourcing-scripts

Member

jjallaire commented Jul 15, 2018

No, you would write a Python function, source the script containing the function, then call the function from R. See https://rstudio.github.io/reticulate/articles/calling_python.html#sourcing-scripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment