From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vikas Rawal Subject: Re: NA in R source code block Date: Sat, 31 Mar 2018 18:13:40 +0530 Message-ID: References: <87h8owlp0r.fsf@gmail.com> <87tvswju97.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 11.1 \(3445.4.7\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_7DF411AE-5D5F-4FD0-9DB7-A5D8E9046438" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f2FrK-0000GL-9k for emacs-orgmode@gnu.org; Sat, 31 Mar 2018 08:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f2FrG-0008MG-CO for emacs-orgmode@gnu.org; Sat, 31 Mar 2018 08:43:50 -0400 Received: from mail-pf0-x232.google.com ([2607:f8b0:400e:c00::232]:46468) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f2FrG-0008Ly-23 for emacs-orgmode@gnu.org; Sat, 31 Mar 2018 08:43:46 -0400 Received: by mail-pf0-x232.google.com with SMTP id h69so7042719pfe.13 for ; Sat, 31 Mar 2018 05:43:45 -0700 (PDT) In-Reply-To: <87tvswju97.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Jeremie Juste Cc: org-mode mailing list --Apple-Mail=_7DF411AE-5D5F-4FD0-9DB7-A5D8E9046438 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 >=20 > ### Solution 1 >=20 > 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. >=20 > I don't know how to implement it automatically though.=20 >=20 > #+BEGIN_SRC_elisp > (defun removenil (x) > (interactive) > (replace-regexp-in-string "nil" "" x)) > #+END_SRC >=20 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=3D"") { > dt[is.na(dt)] <- rep > return(dt) > } > NA_rep(data.frame(a=3Dc(1,2,NA),b=3Dc("john","dan","marco"))) > #+END_SRC >=20 This gets more painful if I want to use something like =E2=80=9C=E2=80=94=E2= =80=9C in numeric columns. The first approach/export filter is less painful than this. Thanks, Vikas --Apple-Mail=_7DF411AE-5D5F-4FD0-9DB7-A5D8E9046438 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

### 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=3D"") = {
dt[is.na(dt)] <- rep
return(dt)
}
NA_rep(data.frame(a=3Dc(1,2,NA),b=3Dc("john","dan","marco")))
#+END_SRC


This gets more = painful if I want to use something like =E2=80=9C=E2=80=94=E2=80=9C in = numeric columns.

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

Thanks,

Vikas


= --Apple-Mail=_7DF411AE-5D5F-4FD0-9DB7-A5D8E9046438--