Skip to content

Using ExeTera With R

deng113jie edited this page Jun 22, 2021 · 10 revisions

Python and R

The analytics API is written in python, but should be usable though R via reticulate. Detailed examples of how to do this will be provided as soon as possible.

Known limitations

It is possible to access ExeTera DataFrames and Fields through R but as it stands, it is not possible to write to Fields or change the contents of DataFrames. This is due to Reticulate requiring that all interaction with Reticulate-wrapped python objects being manipulated only on the thread on which it runs. We are looking at techniques to work around this.

Accessing ExeTera through ExeTera-R-Wrapper

Environment Setup

Under the development stage, the ExeTera-R-Wrapper is loaded using devtools:

library(devtools) # load devtools

load_all('/home/jd21/codes/exetera') # path to the source code of ExeTera-R-Wrapper

Once loaded, you can call ExeTera objects from R (note the '$' sign instead of '.'), for example

exetera$core$dataframe$copy()

In the future, we may consider build and install so that you can install ExeTera-R-Wrapper as a independent library.

Session

Once you loaded the ExeTera-R-Wrapper, you should be able to create a ExeTera session instance.

session = Session()

Note the proper way of opening a session is through the python 'with' statement. Without a R-equivalent, please do remember to close the session manually in the end of your code, to make sure the HDFS file is properly close.

session$close()

ExeTera DataSet

source = session$open_dataset('abc.h5', 'r+', 'source') output = session$open_dataset('playground.hdf5', 'w', 'output')

ExeTera DataFrame

Fields

This example shows how you can access data from a given field (WORK IN PROGRESS!).

library(reticulate) 
use_virtualenv("avirtualenv") 
bi = import_builtins() 
all = bi$slice(NULL) 
exetera = import("exetera") 
s = exetera$core$session$Session() 
src = s$open_dataset('adataset.hdf5', 'r', 'src') 
s$get(src['adataframe']['afield'])$data[all])
Clone this wiki locally