I’m using KNIME to process some data and to finally create a report from the processed data. My idea was to use the R package “pander” to collect the chapters and finally export everything with pandoc to HTML or PDF or so. This fails rather unexpectedly, because the R node does not find pandoc. Running R directly, it is found, though.
So I searched around a little bit, and found that the system path environment is clobbered in the KNIME node.
As you can see, the R home path is added at the head of the list. (I removed the actual path for privacy, but it is correct.) Also: this is on Windows. So backslashes and semicolons are correct as well.
The trailing “null” makes me think, that something goes wrong when starting up the R process. I also didn’t find a place, where to specify an environment variable and possibly override the value.
Is that a bug? Does someone know how to “reset” the environment variable from inside R, so that packages like pander pick up the changed setting?
Ah. The markdown messed up the slashes. Of course there are double backslashes there. It was eaten by Markdown and now I cannot edit the post anymore. The right output was like so:
I’ve developed an R package that uses git under the hood. It was working perfectly from within Rstudio but not in Knime.
I’ve tried to debug it into Rserve. It was working fine.
After some investigations, I found that R snippets into Knime are not able to read you Windows PATH environment variable.
You can check this by comparing the output ofSys.which(“R”)orSys.which(“Git”)orSys.which(“pandoc”)` into RStudio and Knime. These will return an empty string in KNIME instead of the full path.
To circumvent this problem you can use the following trick : write a new environment variable in your .Renviron file that point to the proper executable file. And then adapt the package you want to use so that it actually makes use of this environment variable.
Example
Let’s say I want my KNIME R snippet be able to work with pander (and so pandoc.exe).
Open Rstudio and execute Sys.which("pandoc")
copy the path returned by R
Open the user .Renviron file and append the following line without the quotation marks (make sure to edit the path according to what was returned by your Sys.which("pandoc") command):
“MY_PANDOC_EXE="C:\\Users\\MYUSERNAME~1\\AppData\\Local\\Pandoc\\pandoc.exe”
save and close the .Renviron file and restart Rstudio.
Fork pander package, clone it locally and edit helpers.R file and replace the last path_to_pandoc function by the following lines :
path_to_pandoc = function(){
bin = Sys.getenv("MY_PANDOC_EXE")
bin
There could be a better way to achieve this without the need to fork and edit the packages. This is more a quick fix than a true solution but at least it helped me to solve my issue.