emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Vikas Rawal <vikaslists@agrarianresearch.org>
To: Jeremie Juste <jeremiejuste@gmail.com>
Cc: org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: NA in R source code block
Date: Sat, 31 Mar 2018 18:13:40 +0530	[thread overview]
Message-ID: <F6DEA2D4-6F13-4CB1-8FE3-5F9A48F4A499@agrarianresearch.org> (raw)
In-Reply-To: <87tvswju97.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1301 bytes --]


> 
> ### Solution 1
> 
> You could use an elisp function to clear the nil. It is not automatic
> and you would have to write a formula for every column but it might
> still be better changing them manually.
> 
> I don't know how to implement it automatically though. 
> 
> #+BEGIN_SRC_elisp
> (defun removenil (x)
> (interactive)
> (replace-regexp-in-string "nil" "" x))
> #+END_SRC
> 


I created this export filter which uses something similar but automatically replaces nil with --- on all my documents:

(defun org-export-blanks-filter-latex (row backend info)
  "Replace nil in table with --- in LaTeX export."
  (when (org-export-derived-backend-p backend 'latex)
    (replace-regexp-in-string "nil" "---" row)))

(add-to-list 'org-export-filter-table-row-functions
             'org-export-blanks-filter-latex)


> #+NAME: test2
> #+BEGIN_SRC R :results value  :exports results :colnames yes :hline yes :dir /tmp  :session R-test1
> NA_rep <- function(dt,rep="") {
> dt[is.na(dt)] <- rep
> return(dt)
> }
> NA_rep(data.frame(a=c(1,2,NA),b=c("john","dan","marco")))
> #+END_SRC
> 

This gets more painful if I want to use something like “—“ in numeric columns.

The first approach/export filter is less painful than this.

Thanks,

Vikas



[-- Attachment #2: Type: text/html, Size: 14921 bytes --]

      reply	other threads:[~2018-03-31 12:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-29 11:35 NA in R source code block Vikas Rawal
2018-03-31  6:47 ` Jeremie Juste
2018-03-31  7:57   ` Vikas Rawal
2018-03-31 12:37     ` Jeremie Juste
2018-03-31 12:43       ` Vikas Rawal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F6DEA2D4-6F13-4CB1-8FE3-5F9A48F4A499@agrarianresearch.org \
    --to=vikaslists@agrarianresearch.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=jeremiejuste@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).