Search code examples
pythonrsnowflake-cloud-data-platformrpy2

Importing libraries into snowpark


I want to know if there's any experience out there of importing rpy2 and using R within snowpark?

​ I want to be able to use some common R functionality within snowpark via python code (and the relevant libraries).

​ Not sure if it's possible. ​​

I'm completely new to snowpark and don't yet understand the process of importing additional libraries.​


Solution

  • It's not currently possible to import rpy2 as a custom package in Snowpark as it relies on native system libraries. This article is useful in understanding how to import Python packages for use within Snowflake if they are not already available in the Snowpark Anaconda channel for use in Snowflake. rpy2 also requires an R installation to be installed separately which the rpy2 packages uses, and R is not currently available within the protected environment that Snowpark code executes on in Snowflake Virtual Warehouses. You would also need to install any R packages that your R code uses within that environment if your using additional R packages to base.

    If you have some ML models trained externally in R which you would like to execute predictions with inside Snowflake it may be possible to export and package them using one of the model exchange formats e.g. onnx and use python's support for onnx in Snowpark to execute them.