I guess you can easily interact with a R instance in the QGis python console using rpy2
.
Try these following lines of code in the QGIS python console:
>>> import rpy2.rinterface as rinterface
>>> rinterface.set_initoptions((b'rpy2', b'--no-save'))
>>> rinterface.initr()
0
>>> from rpy2.robjects.packages import importr
>>> import rpy2.robjects as robjects
You can now interact with R like this :
>>> robjects.r("""seq(1,12);""")
<IntVector - Python:0x7fa5f6e4abd8 / R:0x769f4a8>
[ 1, 2, 3, ..., 10, 11, 12]
Or import some libraries for example :
>>> rutils = importr("utils")
>>> rgraphics = importr('graphics')
Take a look at the documentation of Rpy2, I have successfully used these methods to run some personals scripts or some libraries installed from the CRAN (running multiple statements in robjects.r("""...""")
and grabbing the output in a python variable to use in QGIS).
(If i remember well, on windows I had to set some environnement variables first, like R_HOME
or R_USER
maybe)
Also, if you haven't seen it, take a look at this page of the QGIS documentation : 17.31. Use R scripts in Processing. It offers a convenient way to use your existing R script with some slight add.