Metaprogramming in R
While reworking the DCE Simulation package for my Thesis, I’ve discovered one more interesting topic to speak about. We have already seen how to create a package, write documentation and implement OOP in R. Now it comes the time of Metaprogramming. But don’t be afraid of this unfamiliar term, we are going to see that the concepts behind it are fairly simple.
Most of the materials presented are adopted from this mazing book about advanced R. My task here is mostly the vulgarisation of the material.
OOP in R
In previous publications we have seen how to create a package with R: (1) the project’s structure generation, (2) the unit tests and their automation and (3) the documentation management. Now its time to dive deeper into programming with R. Today we are going to explore how one can use Object Oriented Programming (OOP) paradigm in R.
There exist multiple object types and programming conventions, each with a particular idea behind it. In this post we are going to explore their differences and see when each of them is more appropriate.
Package documentation in R
Previously we have seen how to create a package: how to structure your code, what files to include and how to test your code.
The next step in package creation is the documentation.
We have spoken about its existence, but only briefly.
Now we have some more time to describe the documentation mantainace procedure more in detail.
For this we are going to use the roxygen2 package, which is included in devtool suite.
Tests in R
Following the previous post about the package creation in R we are going to dive into some details about how to work with packages. The first thing of interest for us is the possibility to perform tests on the package’s contents in order to control the result. Such possibility greatly facilitates the workflow while creating a package and ensures its functionality.
What is testthat?
Focusing our attention on the devtools meta-package’s contents we encounter rather quickly a great number of tools to test packages.
One of the key element here is the testthat package, which has a number of functions to perform tests.
Among the advantages listed on the project’s official webpage we discover testthat is, as it:
Python alongside R
While working on my PhD thesis I’m usually facing the situation when I need to use both R and Python programming languages.
R offers me the possibility to render neat scientific supports with rmarkdown package, which bring .Rmd support.
Obviously, Python has similar format (pymarkdown and the .Pmd) available, it is not as well developed as the R counterpart.
Moreover, I’m far more familiar with R statistical libraries, tidyverse suite and coding practices.
However, at the same time I need Python dependencies: the most developed neural network (NN) libraries are written in Python or have their main interface in Python.
For example, the well known TensorFlow has a Python based backend.
LaTeX and R
Today I’ve had to complete one of the course deliverables with some indications about how to compile the .Rmd files.
The courses I’m giving (partially) at Grenoble INP Génie Industriel (GI) are mostly oriented for the first and second year students on the engineering track.
This means that the level of heterogeneity in the knowledge across the groups is extreme and while some of them are more than capable to use R for document compilation, others encounter difficulties with this task.
Financial market analysis with R
Recently I’ve became obsessed with the idea of getting into stock exchange (for testing purposes and not for actual investment). One of the main reasons is the desire to start putting something aside for long-term perspective, but in short perspective this project gives me quite a lot of things to play with. Among them - the possibility to explore the predictive financial oriented models, neural networks (NN) testing for stock predictions and many more.
Bibliometrix
Since the start of my Doctoral studies I’ve always performed the literature exploration “the hard way”. Meaning, that I’ve performed most of my literature searches by hand, attempting to manually locate the key articles in the domain. While I’ve got an in-depth comprehension of the field, it remains possible that I’ve overlooked some of interesting literature clusters. However, there always existed a possibility to avoid such mistakes: by performing a thorough bibliometrics study instead of the simple literature overview.
RStudio or VS Code
It’s highly probable, that the days to come will be marked with a lot of activity on this blog. Some of the last discussions pushed me forward to start publishing on several topics I’ve considered as not worth of it. Among the most interesting points comes the discussion of the R related ecosystem. This topic regroups both the discussion about the FOS Software, as well as the R language itself.