KentonWhite / ProjectTemplate

A template utility for R projects that provides a skeletal project.
http://projecttemplate.net
GNU General Public License v3.0
622 stars 159 forks source link

RStudio: Interleaved Python and R Code Execution with Reticulate #314

Closed UTexas80 closed 7 months ago

UTexas80 commented 7 months ago

Types of change

Pull request checklist


Proposed changes

Interleaved Python and R Code Execution with Reticulate

Purpose: This test case verifies the ability of RStudio to seamlessly execute Python code interspersed with R code in a sequential order. The test utilizes the reticulate package to facilitate communication between R and Python environments.

Scope:

Test Design:

1. Test Environment:

2. Test Data:

3. Test Steps:

  1. Create a temporary project directory.
  2. Create a subdirectory named "munge" to store Python and R scripts.
  3. Define two python test scripts:
    • 01-test_data.py: Imports pandas and os, creates a dataFrame data, writes it to a CSV file (test_data_py.csv) and performs a calculation (e.g., sum of a column) and prints the result.
    • 02-test_data.py: Imports pandas, os and sys, reads/writes the CSV file test_data_py.csv) created in 01-test_data.py, creates a dataframe py_data, defines a variable subdirectory, checks if the subdirectory variable exists in the python environment, passes the result to a variable data, prints whether y or n, writes a dynamically named dataframe either y.csv or n.csv to the munge subdirectory
  4. Write the scripts to their respective files within the "munge" directory.
  5. Use reticulate's source function to sequentially load the Python scripts from the R Project Template package.
  6. Verify if the CSV files created by the Python script exist using except_false and file.exists from the testthat package.
  7. Verify if the python variables exist in the R environment using except_false from the testthat package.
  8. Execute the python script (01-test_data.py) to test capturing of the Python calculation result.
  9. Execute the R script (01-test_data.R) to test capturing of the R result tibble.
  10. Execute the python script (02-test_data.py) to test capturing of the Python environment result.
  11. Execute the R script (02-test_data.R) to test capturing of the R result tibble.

4. Expected Results:

5. Pass/Fail Criteria:

Additional Considerations:

Conclusion: This test case demonstrates the basic functionality of running Python code interspersed with R code using reticulate. By successfully passing this test, we gain confidence in RStudio's ability to integrate Python code within the R environment, allowing for flexible data analysis workflows that leverage the strengths of both languages.

UTexas80 commented 7 months ago

Hello @KentonWhite

My changes for the ProjectTemplate "Interleaved Python and R Code Execution in RStudio" are ready for your review.

If you have any questions, comments, or concerns please let me know.

Thank you for your time and consideration.

Regards,

Glen @UTexas80

UTexas80 commented 7 months ago

Hello @KentonWhite

My changes for the ProjectTemplate "Interleaved Python and R Code Execution in RStudio" are ready for your review.

If you have any questions, comments, or concerns please let me know.

Thank you for your time and consideration.

Regards,

Glen @UTexas80