RStudio 1.2 `NA` show up as 0 in dataframe viewing tab

Hi,

I am using RStudio v1.2.1139-1. When I load a csv into R, blank cells that should show up as NA show up as 0. I started with a new blank csv file and tried loading it using:

  • read.csv (base R)
  • read_csv (readr)
  • fread (data.table)

and then I saved it as an .xlsx file and loaded it using:

  • read_excel (readxl)

and the blank cells show up as 0 when view the dataframe by selecting it from the Global Environment window in the top right corner.

When I print the data on the console, it prints with NA. So it seems to me that the viewer is showing it incorrectly (unless it was designed to show 0 instead of NA?) as the data seems to print correctly and performing operations on NA values results in NA.

Has anyone else come across this problem? Here is sample code that produces the issue.

Thanks,

# when viewing dataframe from Global Environment NA show up as 0
a <- data.frame(columnA = c(1:5, rep(NA, times = 4), 10),
                columnB = rep("apples", times = 10),
                columnC = c(11, 12, NA, 14, NA, NA, NA, 18, 19, 20))

sessionInfo()
#> R version 3.5.1 (2018-07-02)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 7 x64 (build 7601) Service Pack 1
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.1252 
#> [2] LC_CTYPE=English_United States.1252   
#> [3] LC_MONETARY=English_United States.1252
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_3.5.1  backports_1.1.2 magrittr_1.5    rprojroot_1.3-2
#>  [5] tools_3.5.1     htmltools_0.3.6 yaml_2.2.0      Rcpp_0.12.18   
#>  [9] stringi_1.2.4   rmarkdown_1.10  knitr_1.20      stringr_1.3.1  
#> [13] digest_0.6.15   evaluate_0.11
2 Likes

Could you please provide us with a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

Hi Kevin,

I included a sample of the code on the forum. Anything else please let me know!

Thanks for RStudio!

Great; thanks! I've reproduced this; we're tracking a similar and likely related issue at https://github.com/rstudio/rstudio/issues/3940.

Any chance that the Global Environment viewer pane can also have adjustable column widths? I believe that was brought up before but that would just be awesome!

That is about the only 'negative' feature I can think of in RStudio for everything I use it for. :):grinning:

Thanks for your help!

Would you mind filing a feature request, so we don't lose track of this?

A feature request to show blank cells as NA instead of 0 in the viewer tabs from the Global Environment?

It appears it already is #3964

I meant your comment re: adjustable widths for columns in the Environment pane.

Holy, sorry. I must have missed this notification that you had responded.

Yes, I will add that issue in. Thanks!

I just posted it. Thanks.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.