Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data.table objects aren't updated in Rstudio environment panel

A data.table object in the environment panel will not update its preview after new variables are added using the := method. However str(dt) shows the correct details, and assigning dt to a new variable results in the correct preview in the Environment panel.

dt <- data.table(x = 1:10,
                 y = log(1:10),
                 z = (1:10)**2)
dt[, a := x + y, ]
dt[, b := x + z, ]
str(dt)
d <- dt

Is this by design, a known bug or is there a solution to this? The behavior is interesting, and I am curious as to the reason this is happening.

like image 927
Mitch Avatar asked Mar 10 '16 15:03

Mitch


People also ask

How do I refresh global environment in R?

You can do both by restarting your R session in RStudio with the keyboard shortcut Ctrl+Shift+F10 which will totally clear your global environment of both objects and loaded packages.

Why is my environment not showing in R?

The cause of this problem is usually that the right panes have been minimized. They can be restored by dragging the gripper that separates the right panes from left panes.

What is an environment object in R?

An environment is just a place to store variables – a set of bindings between symbols and objects. If you start up R and make an assignment, you're adding an entry in the global environment. > a <- 1234. > e <- globalenv()


1 Answers

Looks like RStudio only updates environment panel when objects are created, or when you hit refresh button (as pointed by @lukeA).
I don't think the bug is good word here, it can be a design concept of RStudio to update structure of objects only in particular scenario, and not investigate what each user's call is, to decide if refresh is required.
But I understand it is not desired behavior for RStudio users, but I think it better fits as feature request to detect by reference calls than a bug report.

This behavior is consistent comparing to dir.create() which creates directory as a side effect. It is also not updated in working directory panel always.

like image 129
jangorecki Avatar answered Sep 27 '22 18:09

jangorecki