Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Flash Gordon
May 8, 2006
Death To Ming
I'm using Spacemacs and despite it having an ess layer I'm having trouble getting it to play nicely with .Rnw files. There doesn't seem to be a easy command that will knit the file and create a pdf. I am trying to put something in my user config so that I can just type SPC-m-o-c and it will run the commands:

code:
Rscript -e "library(knitr); knit('filename.Rnw')" && pdflatex filename.tex
but I can't seem to get it to work. Here is what I currently have, it gives me an error about 'wrong type argument: stringp, nil'.:

code:
  (add-to-list 'auto-mode-alist '("\\.Rnw\\'" . Rnw-mode))
  (defun custom-knit ()
    (let ((rnw-file))
      (setq rnw-file (buffer-file-name))
      (concat "Rscript -e \"library(knitr); knit('" rnw-file
              "')\" && pdflatex " (file-name-base buffer-file-name) ".tex")
      )
    )
  (spacemacs/set-leader-keys-for-major-mode
    'Rnw-mode "moc" (shell-command (custom-knit)))
EDIT: Alright, got it working by adding the following two items to my .spacemacs:

code:
;; in user-init()
  (setq ess-swv-processor "knitr")
  (setq ess-swv-pdflatex-commands (quote ("pdflatex" "texti2pdf" "make")))

;; in user-config()
  (spacemacs/set-leader-keys "moc" '(lambda () (interactive)
                                      (ess-swv-PDF "pdflatex")))
I still need to manually start an R instance when I open up a .Rnw file (and it doesn't seem to switch to the proper major mode automatically) but it's close!

Flash Gordon fucked around with this message at 02:25 on Mar 3, 2016

Adbot
ADBOT LOVES YOU

  • Locked thread