-
Notifications
You must be signed in to change notification settings - Fork 4
Using ExeTera With 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.
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.
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.
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()
source = session$open_dataset('abc.h5', 'r+', 'source') output = session$open_dataset('playground.hdf5', 'w', 'output')
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])