From: Jeremie Juste <jeremiejuste@gmail.com>
To: Vikas Rawal <vikaslists@agrarianresearch.org>
Cc: org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: NA in R source code block
Date: Sat, 31 Mar 2018 14:37:40 +0200 [thread overview]
Message-ID: <87tvswju97.fsf@gmail.com> (raw)
In-Reply-To: <F082EC72-2220-45AA-9486-46179141E35B@agrarianresearch.org> (Vikas Rawal's message of "Sat, 31 Mar 2018 13:27:09 +0530")
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 “nil” at the time of export and
> replaces it with a “---“. But that is not perhaps the most efficient
> way of doing it.
>
> Warmly,
>
> Vikas
>
> -----------
>
> #+NAME: test
> #+BEGIN_SRC R :results value :exports results :colnames yes :hline yes
>
>
> data.frame(a=c(1,2,NA),b=c("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.
#+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 :dir /tmp :session R-test1
data.frame(a=c(1,2,NA),b=c("john","dan","marco"))
#+END_SRC
#+RESULTS: test
| a | b |
|---+-------|
| 1 | john |
| 2 | dan |
| | marco |
#+TBLFM: $1='(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 :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
#+RESULTS: test2
| a | b |
|---+-------|
| 1 | john |
| 2 | dan |
| | marco |
Best regards,
Jeremie
next prev parent reply other threads:[~2018-03-31 12:37 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 [this message]
2018-03-31 12:43 ` Vikas Rawal
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=87tvswju97.fsf@gmail.com \
--to=jeremiejuste@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=vikaslists@agrarianresearch.org \
/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).