1

When using R in org mode source blocks, any NA (i.e. missing) values in tables get replaced with nil. Why is this?

And is there a way to change this (globally, or at the file level)? I regularly create reports using Org Babel that are to be read by non-Org users and while they do understand NA, nil means nothing to them.

2

I believe the reason lies in org-babel-R-write-object-command

(defconst org-babel-R-write-object-command "{
    function(object,transfer.file) {
        object
        invisible(
            if (
                inherits(
                    try(
                        {
                            tfile<-tempfile()
                            write.table(object, file=tfile, sep=\"\\t\",
                                        na=\"nil\",row.names=%s,col.names=%s,
                                        quote=FALSE)
                            file.rename(tfile,transfer.file)
                        },
                        silent=TRUE),
                    \"try-error\"))
                {
                    if(!file.exists(transfer.file))
                        file.create(transfer.file)
                }
            )
    }
}(object=%s,transfer.file=\"%s\")"

Try changing na=\"nil\" to na=\"NA\" or removing that argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.