3

I have a script called DataRetrieval.py. This script connects to an internal database, retrieves data and writes that data to an Excel file. This script imports the following:

a) a utils.py helper module that contains several functions

b) a DataRetrieval.cfg configuration file (which contains all of the login information and SQL queries that the DataRetrieval.py script needs)

The DataRetrieval.py script takes the following 3 command line arguments:

DataRetrieval.py   DataRetrieval.cfg   03/01/20

(the script itself, the configuration file, and a start date)

I would like to use the Reticulate package in R to:

  1. call each of these 3 command line arguments
  2. set the output of the script (which is an Excel file) to an object (the end goal is to call this object in a Shiny dashboard)

I was thinking about using the source_python() function, but I don't think it allows for multiple positional arguments. The error message returns:

> source_python("DataRetrieval.py")
Error in py_run_file_impl(file, local, convert) : SystemExit: 2
usage: python.exe [-h] [-e ENDDATE] config startDate
python.exe: error: the following arguments are required: config, startDate

What is the best way to use the Reticulate package to call these 3 command line arguments? Perhaps a single .py file that encapsulates each of the 3 arguments above?

Thanks!

2
  • 1
    Why use reticulate and not a command line call with system() especially if you do not need any Python objects in R environment? Commented Mar 13, 2020 at 22:29
  • The end goal is to use Shiny. Our internal API is not exposed to R. Therefore, the use of Reticulate. How does one use system() in that setting? Commented Mar 14, 2020 at 0:55

1 Answer 1

2

EDIT: I solved this problem by creating a .py file named retrieve.py and passing that file to the source_python() Reticulate function. The retrieve.py file reads as follows:

import os

os.system('python DataRetrieval.py DataRetrieval.cfg 02/01/20')
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.