From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeremie Juste Subject: Re: NA in R source code block Date: Sat, 31 Mar 2018 14:37:40 +0200 Message-ID: <87tvswju97.fsf@gmail.com> References: <87h8owlp0r.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f2FlU-0004E1-Er for emacs-orgmode@gnu.org; Sat, 31 Mar 2018 08:37:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f2FlP-0003n7-Gt for emacs-orgmode@gnu.org; Sat, 31 Mar 2018 08:37:48 -0400 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:46505) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f2FlP-0003mE-A5 for emacs-orgmode@gnu.org; Sat, 31 Mar 2018 08:37:43 -0400 Received: by mail-wr0-x232.google.com with SMTP id d1so9879217wrj.13 for ; Sat, 31 Mar 2018 05:37:43 -0700 (PDT) In-Reply-To: (Vikas Rawal's message of "Sat, 31 Mar 2018 13:27:09 +0530") 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: Vikas Rawal Cc: org-mode mailing list Hello, I don't have an ideal org-mode solution for this problem. I suggesting two ways hoping that more improvements will come > Here is an example. The NA in column a shows up in the results as > nil. Why does that happen? Is there a way of changing this behaviour? > I can manually replace NA with something else, but doing that in each > code block is a pain. Since I wrote my first mail, I have written an > export filter that filters out each =E2=80=9Cnil=E2=80=9D at the time of = export and > replaces it with a =E2=80=9C---=E2=80=9C. But that is not perhaps the mos= t efficient > way of doing it. > > Warmly, > > Vikas > > ----------- > > #+NAME: test > #+BEGIN_SRC R :results value :exports results :colnames yes :hline yes > > > data.frame(a=3Dc(1,2,NA),b=3Dc("john","dan","marco")) > > #+END_SRC > > #+RESULTS: test > | a | b | > > |-----+-------| > | 1 | john | > | 2 | dan | > | nil | marco | ## Some suggestions ### 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.=20 #+BEGIN_SRC_elisp (defun removenil (x) (interactive) (replace-regexp-in-string "nil" "" x)) #+END_SRC #+NAME: test #+BEGIN_SRC R :results value :exports results :colnames yes :hline yes :di= r /tmp :session R-test1 data.frame(a=3Dc(1,2,NA),b=3Dc("john","dan","marco")) #+END_SRC #+RESULTS: test | a | b | |---+-------| | 1 | john | | 2 | dan | | | marco | #+TBLFM: $1=3D'(removenil $1); ### Solution 2 You could easily replace the NA in R before output. For instance #+NAME: test2 #+BEGIN_SRC R :results value :exports results :colnames yes :hline yes :di= r /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 #+RESULTS: test2 | a | b | |---+-------| | 1 | john | | 2 | dan | | | marco | Best regards, Jeremie