I am trying to evaluate R code within LaTeX code in an org-mode document. The objective is to export the org-mode document to a .tex document and, ultimately, to a nice pdf document.

My problem is that I cannot get the R code to be evaluated when it is placed within LaTeX code in the org-mode document.

If you run my MWE below you will see what I mean, i.e., the pdf produced does not contain the values 4 and 3 in place of the R inline code that lives within the LaTeX code

How could I possibly accomplish this feat?

    # -*- find-file-hook: org-babel-execute-buffer -*-
    #+TITLE: My Minimal Working Example (MWE)
    #+AUTHOR: Daangui
    #+PROPERTY: header-args :tangle yes
    #+PROPERTY: header-args:R :session *R* 

    Here I create some data in R:

    #+HEADER: :dir ~/temp
    #+begin_src R :exports code
    x <- (1:10)

    Now I try to show something nice in /LaTeX/: 

    $100 \times \left( \frac{src_R{x[4]}}{src_R{x[3]}} - 1 \right) =$
    src_R{100*(x[4]/x[3])-100} % increase!

I could add [:exports results] or [:results latex] as options to src_R and still, I would not get the results of evaluating x[4] and x[3], i.e., the numbers 4 and 3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.