Use SWI-Prolog from R
Full documentation at PDF or HTML
To call prolog from Rmd files and generate prolog based reports from RStudio.
First of all, install SWI-Prolog. Make sure swipl binary is in your path.
I tested it once on windows. I manly use it from Linux. 64bit Windows seemed to miss swipl.exe, but 32bit worked fine. In case windows version looks broken and you need it, let me know!
Then you can install the R package:
# you need devtools, did you try install.packages(devtools) ?
devtools::install_github("https://github.com/battmanux/swiplr.git")
Load R library
# this is an R chunk
library(swiplr)
Add a prolog chunk
% this is some prolog code
foo(bar).
foo(other).
% define queries by starting lines with ?-
?- foo(X).
|FOO | |:-----| |bar | |other |
This returns a nice table foo_list
that you can use from R
# This is some R code calling prolog output
# R variable is named after prolog chunk label
str(foo_list)
'data.frame': 2 obs. of 1 variable:
$ FOO: chr "bar" "other"
path <- system.file("swiplPy.py", package = "swiplr")
cat("Add this path for python libs: ", path)
sys.path.append("/usr/local/lib/R/site-library/swiplr/")
import swiplPy
swipl = swiplPy.swiplPy()
swipl.query(code="foo(bar).", query="foo(X)")
del swipl
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.