Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to turn off ansi code coloring of console output #395

Closed
plantarum opened this issue Mar 16, 2018 · 8 comments
Closed

Option to turn off ansi code coloring of console output #395

plantarum opened this issue Mar 16, 2018 · 8 comments

Comments

@plantarum
Copy link

I'm using Emacs, with my R code embedded in orgmode documents. When I use the :session option for the code block, R runs it using the ESS package. ESS supports ANSI color codes, R can detect that, and the console output is colored accordingly. However, when the output is transferred back to original org document, the ansi codes are inserted as characters.

It may be possible to fix this on the Emacs side, but it would be nice to have a way to turn off the escape codes from the R side.

Here's an example file to demonstrate what I see from Emacs:

* Reproducible Example

Start with ~emacs -Q~, then evaluate each of the following code blocks
in turn.

#+BEGIN_SRC elisp setup
(require 'package)
(setq package-load-list
      '((org-plus-contrib t)
	(ess t)
	(julia-mode t)))
(package-initialize)
(require 'org)
(require 'ess)

(org-babel-do-load-languages
 'org-babel-load-languages
 '((emacs-lisp . t)
   (R . t)
   (shell . t)))
#+END_SRC

#+RESULTS:

If you don't already have ~tidyr~ and ~dplyr~ installed, you need to
do that before running the following:

#+BEGIN_SRC R :results output
library(tidyr)
library(dplyr)
as_tibble(iris)
#+END_SRC

#+RESULTS:
#+begin_example
# A tibble: 150 x 5
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
          <dbl>       <dbl>        <dbl>       <dbl> <fct>  
 1         5.10        3.50         1.40       0.200 setosa 
 2         4.90        3.00         1.40       0.200 setosa 
 3         4.70        3.20         1.30       0.200 setosa 
 4         4.60        3.10         1.50       0.200 setosa 
 5         5.00        3.60         1.40       0.200 setosa 
 6         5.40        3.90         1.70       0.400 setosa 
 7         4.60        3.40         1.40       0.300 setosa 
 8         5.00        3.40         1.50       0.200 setosa 
 9         4.40        2.90         1.40       0.200 setosa 
10         4.90        3.10         1.50       0.100 setosa 
# ... with 140 more rows
#+end_example

The results run in batch mode are fine. But if we try to use a session:

#+BEGIN_SRC R :results output :session RSESSION
library(tidyr)
library(dplyr)
as_tibble(iris)
#+END_SRC

#+RESULTS:
#+begin_example

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union
�[90m# A tibble: 150 x 5�[39m
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
          �[3m�[90m<dbl>�[39m�[23m       �[3m�[90m<dbl>�[39m�[23m        �[3m�[90m<dbl>�[39m�[23m       �[3m�[90m<dbl>�[39m�[23m �[3m�[90m<fct>�[39m�[23m  
�[90m 1�[39m         5.10        3.50         1.40       �[90m0�[39m�[90m.�[39m200 setosa 
�[90m 2�[39m         4.90        3.00         1.40       �[90m0�[39m�[90m.�[39m200 setosa 
�[90m 3�[39m         4.70        3.20         1.30       �[90m0�[39m�[90m.�[39m200 setosa 
�[90m 4�[39m         4.60        3.10         1.50       �[90m0�[39m�[90m.�[39m200 setosa 
�[90m 5�[39m         5.00        3.60         1.40       �[90m0�[39m�[90m.�[39m200 setosa 
�[90m 6�[39m         5.40        3.90         1.70       �[90m0�[39m�[90m.�[39m400 setosa 
�[90m 7�[39m         4.60        3.40         1.40       �[90m0�[39m�[90m.�[39m300 setosa 
�[90m 8�[39m         5.00        3.40         1.50       �[90m0�[39m�[90m.�[39m200 setosa 
�[90m 9�[39m         4.40        2.90         1.40       �[90m0�[39m�[90m.�[39m200 setosa 
�[90m10�[39m         4.90        3.10         1.50       �[90m0�[39m�[90m.�[39m100 setosa 
�[90m# ... with 140 more rows�[39m
#+end_example

@krlmlr
Copy link
Member

krlmlr commented Mar 16, 2018

@lionel-: I remember you are using ESS, could you please take a look?

@lionel-
Copy link
Member

lionel- commented Mar 16, 2018

I don't run R code in org-mode but I think you can set options(crayon.enabled = FALSE) to disable the codes. Can you please confirm tibble uses crayon @krlmlr? I think you should file an issue upstream though (i.e. org-mode).

@krlmlr
Copy link
Member

krlmlr commented Mar 19, 2018

Yes, we use crayon, and options(crayon.enabled = FALSE) works. A fix in EMACS would be nice, because this problem likely affects other packages that produce colored output.

@krlmlr krlmlr closed this as completed Mar 19, 2018
@lionel-
Copy link
Member

lionel- commented Mar 19, 2018

It's not "Emacs" that should be fixed but org-mode ;)

@plantarum
Copy link
Author

Yes, in this context the Emacs side is actually orgmode. I have suggested a fix to the orgmode mailing list. Just waiting on someone there to confirm the problem and agree on my change.

@MilesMcBain
Copy link

@lionel- This problem can be encountered by ESS users without orgmode in the loop. Try ess-R-dv-pprint to output a tibble to a new buffer and you get the same nonsense. It would be nice to be able to turn off the colours as a pillar option rather than having to disable globally.

@lionel-
Copy link
Member

lionel- commented Aug 31, 2018

If it's not possible already, please file an issue.

@github-actions
Copy link
Contributor

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants