rmarkdown/knitr as processor

Konstantin Tennhard's Avatar

Konstantin Tennhard

17 Sep, 2014 04:07 PM


I'm trying to use R in combination with rmarkdown as my preprocessor so I can display markdown documents that contain R cod, which is evaluated during the render process. The script works fine when I call it from the command line:

cat report.md | rmarkdown-wrapper > report.html

But if I run the script from within Marked 2 and redirect STDERR to STDOUT, I get the following message:

/usr/local/bin/R: /usr/local/Library/ENV/4.3/sed: /bin/bash: bad interpreter: Operation not permitted
ERROR: option '-e' requires a non-empty argument

In case I don't redirect the output nothing is returned and Marked performs the default render process.

/usr/local/bin/R is a shell script that performs the option parsing and sets up all necessary environment variables and then initiates the R runtime. At least that is what I deduced from staring at it for a while. My assumption at this point is that there isn't anything wrong with R and it might just come down to a permission problem. Is there any way, I can force Marked to execute a script in my own shell environment, just to see if this would fix the problem?

I also tried Rscript which is usually used for bash execution of R programs. This one seems to be an actual binary. The problem looks is essentially the same:

/usr/local/Cellar/r/3.1.1/R.framework/Versions/3.1/Resources/bin/R: /usr/local/Library/ENV/4.3/sed: /bin/bash: bad interpreter: Operation not permitted
ERROR: option '-e' requires a non-empty argument

Using the following dummy script, also results in an error – a popup with the message "Operation not permitted" appears.

echo 'foo' | /usr/local/bin/gsed 's/foo/bar'

Is Marked not allowed to access anything in /usr/local/bin?

Thanks for any help in advance!

  1. Support Staff 1 Posted by Brett on 17 Sep, 2014 04:32 PM

    Brett's Avatar

    Drag your /usr/local folder from Finder to Marked's icon to allow it


  2. 2 Posted by Konstantin Tenn... on 17 Sep, 2014 04:46 PM

    Konstantin Tennhard's Avatar

    This resulted in Marked just displaying a random file in the folder. The Permission Problem still exists; that is the script still produces the same error.

    Can I reset Marked's permissions?

  3. Support Staff 3 Posted by Brett on 17 Sep, 2014 04:47 PM

    Brett's Avatar

    When it displayed the file, though, did it request permission to access

  4. Support Staff 4 Posted by Brett on 17 Sep, 2014 04:48 PM

    Brett's Avatar

    Also, try also dragging /usr/Library if that directory exists.

  5. 5 Posted by Konstantin Tenn... on 17 Sep, 2014 04:49 PM

    Konstantin Tennhard's Avatar

    No, it didn't. The only time I was asked was when I clicked the "Update Permissions" button in the settings.

  6. Support Staff 6 Posted by Brett on 17 Sep, 2014 04:51 PM

    Brett's Avatar

    If you provided permission when requested by "Update Permissions" then
    this probably isn't a permissions error. I note references to ENV and an
    error related to sed -e, which indicates that the script is loading an
    incorrect version of utilities from within the Marked shell. Note that
    your usual shell environment is unavailable when the custom processor is
    run. The script needs to be able to function without any custom
    environment variables or environment managers (rbenv, pyenv, etc.).


  7. 7 Posted by Konstantin Tenn... on 17 Sep, 2014 04:52 PM

    Konstantin Tennhard's Avatar

    Can I replicate such an environment outside Marked to see if the script functions correctly?

  8. Support Staff 8 Posted by Brett on 17 Sep, 2014 04:57 PM

    Brett's Avatar

    Try running `sudo -s` and entering your password. Your superuser
    environment should be clean enough to test.

  9. 9 Posted by Konstantin Tenn... on 17 Sep, 2014 05:07 PM

    Konstantin Tennhard's Avatar

    Script runs just fine within a sudo shell. It even runs if I invoke it with env -i which resets the environment.

  10. Support Staff 10 Posted by Brett on 17 Sep, 2014 05:10 PM

    Brett's Avatar

    Are you receiving any new/different error messages at this point?

  11. 11 Posted by Konstantin Tenn... on 17 Sep, 2014 05:17 PM

    Konstantin Tennhard's Avatar

    The following "converter" works:

    /usr/local/bin/gecho Hello

    gecho is simply the GNU version of echo and part of the core-utils package I installed via homebrew.

    The following "converter" does not work:

    echo 'Hello' | /usr/local/bin/gsed 's/Hello/World/' 2>&1

    It results in the following error:

    /Users/t6d/bin/Rmarkdown: line 3: /usr/local/bin/gsed: Operation not permitted
  12. Support Staff 12 Posted by Brett on 17 Sep, 2014 05:22 PM

    Brett's Avatar

    What is this?


    And why is a simple gsed call loading it? Are you sure your
    /usr/local/bin/gsed is a hashed binary and not a symlink?

  13. 13 Posted by Konstantin Tenn... on 17 Sep, 2014 05:27 PM

    Konstantin Tennhard's Avatar

    That is my wrapper script. I'm one step closer. Apparently some of the permissions in /usr/local/ were off. Sticky bit was set and the owning group was wheel. I fixed it by using chmod -R. Now I get a new error. mktemp fails. Let me check if I can work it out myself.

    The gsed dummy script does work now.

  14. 14 Posted by Konstantin Tenn... on 17 Sep, 2014 05:37 PM

    Konstantin Tennhard's Avatar

    I'm back to the old issue. While we have been discussing the problem, I'll reinstalled Marked 2 twice, each time with deleting all preferences files, etc. The last time I did so, I didn't immediately click the "Update Permissions" button. I fixed /usr/local and opened it in Marked. I wasn't asked to grant permission, but the echo ... | gsed dummy script worked. My real script, however, now complained that it couldn't create a tempfile using mktemp, so I thought I give this "Update permissions" button a try. Helped to solve the issue that I couldn't access /tmp, but R is still complaining. It is by the way R that uses sed for it's option parsing.

    This is how my script looks by the way. I'm setting HOME just is case, because pandoc which is used by rmarkdown if HOME is not set.

    export HOME=/Users/t6d
    export PATH=/Users/t6d/bin/:/Users/t6d/.cabal/bin:/usr/local/bin:$PATH
    INPUT=`mktemp -t input`
    OUTPUT=`mktemp -t output`
    cat - > $INPUT
    Rscript -e "rmarkdown::render('$INPUT', output_file='$OUTPUT')" 2>&1
    cat $OUTPUT
    unlink $OUTPUT
    unlink $INPUT
  15. 15 Posted by Konstantin Tenn... on 17 Sep, 2014 05:42 PM

    Konstantin Tennhard's Avatar


    Problem is reproducible now. If a file has the following group permissions: rws it will result in an "Operation not permitted" bug.

  16. 16 Posted by Konstantin Tenn... on 17 Sep, 2014 05:44 PM

    Konstantin Tennhard's Avatar

    Simply executing chmod g-s solves the problem. I just missed some files. I don't know how my executables ended up with these permissions in the first place, but I'm happy it works! Sorry, for all the trouble and thank you very much for your help and patience! I'm a big fan of Marked btw. and now that I can directly view my statistics reports, I love it even more!

  17. Support Staff 17 Posted by Brett on 17 Sep, 2014 05:52 PM

    Brett's Avatar

    That's great! I'll leave this up as a reference, hopefully I'll remember
    to link it if I hear about this issue again :).

  18. 18 Posted by Mark Bower on 15 May, 2017 04:43 PM

    Mark Bower's Avatar

    Would it be possible to make the RMarkdown-wrapper available? I, too, would like to run RMarkdown as a Custom Processor in Marked. Thanks!

  19. Support Staff 19 Posted by Brett on 15 May, 2017 05:32 PM

    Brett's Avatar

    Mark, I haven't tested it, but I would think the script in #14 above using Rscript would work… is there an additional wrapper needed?

  20. 20 Posted by Mark Bower on 15 May, 2017 05:54 PM

    Mark Bower's Avatar

    The script (from #14) is not working for me. I made a txt file from the script code listed and made it executable. Should the link to that executable be in the "Processor" or "Pre-processor" tab? The output from Marked 2 do not include results from R, but has a thin red line above R code sections. Where is the error output/log to read what went wrong?

  21. Support Staff 21 Posted by Brett on 06 Jun, 2017 03:02 PM

    Brett's Avatar

    Sorry for the late reply on this, Mark,

    The first thing to check is that the script is working for you from the command line. Run cat your_markdown_file.md | scriptfile.sh > outfile.html (replacing the filenames appropriately) and ensure that the output you're getting is what you're expecting. The resulting outfile.html should be "partial" HTML (not a full document with head/body tags) and should view properly when you load it in a browser.

    Because you're using the script to do the complete render resulting in HTML, you'll want to use it as the Processor. Preprocessors are subsequently run through the selected default processor (Markdown or GFM), so they expect Markdown input.

    You can see the STDOUT/STDERR output of the script within Marked by going to Help->Show Custom Processor Log.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac