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

RStudio: Make sure Environment pane is set to 'Manual Refresh Only' when needed #4

Open
HenrikBengtsson opened this issue Aug 5, 2023 · 2 comments

Comments

@HenrikBengtsson
Copy link
Owner

Idea

Add a tracker that detects when an iter object is being added to the global environment:

> library(iterators)
> x <- iter(1:3)
> class(x)
[1] "containeriter" "iter"

and when we're running RStudio and the RStudio Environment pane is not set to "Manual Refresh Only", because then RStudio calls str(x) in the background, which causes the iterator to be forwarded as if:

> x$state$i
[1] 0

> str(x)
List of 4
 $ state    :<environment: 0x557bea11d740> 
 $ length   : int 3
 $ checkFunc:function (...)  
 $ recycle  :Error in oTypes[[i]] : subscript out of bounds

> x$state$i
[1] 4

The tracker could warn, or even produce an error, saying that iter objects are not compatible with RStudio unless "Manual Refresh Only" is checked in the Environment pane.

See also

@binary10
Copy link

binary10 commented Aug 5, 2023

Hi Henrik, thanks for your attention to this issue. Would it be possible to correct this issue by changing the behavior of the str built-in function? This is the recommendation in the SO post I shared in my issue. Whether one is working with an iterator in RStudio or in another env, as a user I would not expect str to advance the iterator. The purpose of str in the docs is to "Compactly Display the Structure of an Arbitrary R Object", and I would expect this to be possible without side effects.

@HenrikBengtsson
Copy link
Owner Author

HenrikBengtsson commented Aug 5, 2023

Yes, that sounds like a workaround, but best is to update the iterators package. I can also imagine that Posit/RStudio could keep a list of object classes that should be excluded from auto-str() calling.

PS. Note that I am not affiliated with the iterators package, so I cannot make any updates to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants