0

Is it normal that the description in the Global Environment does not update, when I add a column to my data table? And why do I have to call the object twice when I assign it to DT when adding the column?

rm(list=ls()) 
if(!require(data.table)) { install.packages("data.table"); require(data.table)}
DT<-data.table(v1 = runif(50, 0, 10), v2 = runif(50, 0, 10))
DT[,v3:=v1+v2]
DT
DT<-DT[,v4:=v1+v2]
DT
DT
Max M
  • 806
  • 14
  • 29
  • Possible duplicate: http://stackoverflow.com/questions/32988099/data-table-objects-not-printed-after-returned-from-function – Jaap Sep 20 '16 at 15:33
  • 4
    Yes, that's normal (if you refer to the RStudio "Environment" panel). Since the object is not actually grown (due to previous over-allocation), there is no way for RStudio to know that it has been grown. – Roland Sep 20 '16 at 15:34
  • Ok the printing thing seems to be a duplicate. Yes, i am referring to the RStudio "Environment" pane. Why is this normal? And when does it update? – Max M Sep 20 '16 at 15:37
  • 2
    Please study the data.table vignettes and documentation. It's explained there what "over-allocation" and "true length" mean. Why do you care about this? Is anybody actually using that pane? – Roland Sep 20 '16 at 15:50
  • I was, until now, to quickly see the number of rows and columns – Max M Sep 20 '16 at 15:58
  • Interesting. I just use `nrow` and `ncol` or `str` or `summary`. – Roland Sep 20 '16 at 16:09
  • 1
    If you really need to rely on the Rstudio Environment panel, then it has a refresh button you can click before you use it. – dww Sep 20 '16 at 19:22
  • 1
    when providing examples with `runif` or other random stuff use `set.seed`, and don't assign to new variable when you add column by reference with `:=` – jangorecki Sep 21 '16 at 10:54
  • Ok thx for the refresh thing. I will not use this extensively, but i was just surprised that the pane did not updated. I think using the global environment is still worthwhile for the less experienced users that work with small data sets. It is the quickest way to directly see if you code created an object, that is completely unreasonable. I am happy to accept your comments as answer @dracodoc – Max M Sep 21 '16 at 13:29

1 Answers1

2

The question is specific to the Environment pane in RStudio (it's showing global environment in most time, but it can be switched to other environment), then to update the object:

  1. you can click RStudio refresh, though I find it slow and need to refresh everything, especially if you have a lot of huge objects in environment.

  2. you can click the object to open it in data browser, that will show updated data. if the object is already open in data browser, click it again to update. This is much quicker than refresh.

  3. or you can make the data browser as an independent window with the toolbar button show in new window, then right click to refresh this window when needed. This is also quicker than refresh.

dracodoc
  • 2,603
  • 1
  • 23
  • 33