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!

equanimity
  • 2,371
  • 3
  • 29
  • 53
  • Why use `reticulate` and not a command line call with `system()` especially if you do not need any Python objects in R environment? – Parfait Mar 13 '20 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? – equanimity Mar 14 '20 at 00:55

1 Answers1

1

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')
equanimity
  • 2,371
  • 3
  • 29
  • 53