tests/testthat/helper_pandas.R

# helper that load before tests are run

# determine the package directory path
wd = getwd()
package_dir <- gsub("(PythonEmbedInR).*", "\\1", wd)

# import pandas in python
print("Intalling Pandas ...")

# explicitly include the absolute current working directory in the python path
# in order to pick up install_pandas.py across platforms
pyImport("sys")
pyExec(paste("if '", wd, "' not in sys.path: sys.path.append('", wd ,"');", sep=""))

pyImport("install_pandas")

pyExec(sprintf("install_pandas.main('install', '%s')", package_dir))

use_pandas <- function() {  
  # tell PythonEmbedInR to use pandas
  pyExec("import pandas as pd")
  pyOptions("usePandas", TRUE)
  pyOptions("pandasAlias", "pd")
}
Sage-Bionetworks/PythonEmbedInR documentation built on April 17, 2023, 4:23 p.m.