0

I noticed strange behavior in RStudio notebook in R 3.5.1. I can reproduce the behavior by using this code:

list()
head(iris)

At first, an empty list should be printed. Then, if any data frame is printed in either the same or another code chunk, its values get enclosed with additional symbols (some are indicated with arrows) as in this print screen.

In R 3.5.1:

enter image description here

This behavior might be related to this issue with R lists. It is present in notebooks and disappears if the code is run a console or if the document is knitted. In R 3.4.4 this issue is also not present. If additional code is run between the list and data frame, the issue disappears as well, e.g.:

list()
1
head(iris)

I have these questions:

  1. I use Windows. Can Linux and Mac OS users reproduce the issue?
  2. How can the causes of the distortion in the output be explained?
  3. Where should I report the issue if I want it to be solved in the future?

Session info ---------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.1 (2018-07-02)
 system   x86_64, mingw32             
 ui       RStudio (1.1.453)           
 language (EN)                        
 collate  English_United States.1252  
 tz       Europe/Helsinki             
 date     2018-07-15                  

Packages -------------------------------------------------------------------------------------------
 package   * version date       source                          
 base      * 3.5.1   2018-07-02 local                           
 compiler    3.5.1   2018-07-02 local                           
 datasets  * 3.5.1   2018-07-02 local                           
 devtools    1.13.6  2018-06-27 CRAN (R 3.5.0)                  
 digest      0.6.15  2018-01-28 CRAN (R 3.5.0)                  
 graphics  * 3.5.1   2018-07-02 local                           
 grDevices * 3.5.1   2018-07-02 local                           
 knitr       1.20.8  2018-07-07 Github (yihui/knitr@89b34a6)    
 memoise     1.1.0   2017-04-21 CRAN (R 3.5.0)                  
 methods   * 3.5.1   2018-07-02 local                           
 stats     * 3.5.1   2018-07-02 local                           
 tools       3.5.1   2018-07-02 local                           
 utils     * 3.5.1   2018-07-02 local                           
 withr       2.1.2   2018-06-28 Github (jimhester/withr@fe56f20)
 xfun        0.3     2018-07-06 CRAN (R 3.5.0)                  
 yaml        2.1.19  2018-05-01 CRAN (R 3.5.0)  
GegznaV
  • 4,938
  • 4
  • 23
  • 43
  • I don't find this problem in R 3.5.1 on MacBook pro. There is no arrow and the values are printed correctly when you click on the arrow of Run current chunk – akrun Jul 14 '18 at 21:38
  • I tried without knitting and with knitting, both are fine for me – akrun Jul 14 '18 at 21:47
  • Can you provide your `sessionInfo()`, in case there might be something locale-dependent going on? – Kevin Ushey Jul 15 '18 at 07:09
  • @Kevin Ushey, I updated the question with the information you asked for. – GegznaV Jul 15 '18 at 09:11
  • There are a lot packages loaded. Does a restart and only loading relevant packages solve the issue? – jay.sf Jul 15 '18 at 09:19
  • @jaySf I worked on a machine learning project. But when I closed the project, I can still reproduce the problem. The list of packages is smaller now. Thank you for your note. – GegznaV Jul 15 '18 at 09:35

1 Answers1

1

It appears that this is a bug that affects GUI applications using R 3.5.1 on Windows (e.g. RGui and RStudio). For example, you can see a similar effect with:

x <- 1
print(list())
save(x, file = tempfile())
output <- encodeString("apple")
print(output)

Sourcing this gives, for me:

> source('~/encoding.R')
list()
[1] "\002ÿþapple\003ÿþ"

We'll have a fix in the next version of RStudio, but for now the workaround is to just avoid printing empty lists before printing data frames in R.

Kevin Ushey
  • 20,530
  • 5
  • 56
  • 88
  • This is an R bug -- you can see the same issue in RGui 3.5.1, for example (try running the code in my answer there). Fortunately, we can work around this particular issue on the RStudio side. – Kevin Ushey Jul 16 '18 at 21:07
  • 1
    Fortunately t will be fixed in the next versions of R-patched and R-devel thanks to speedy work from Tomas Kalibera (one of the R-core members) – Kevin Ushey Jul 18 '18 at 17:28