tidyverse / reprex

Render bits of R code for sharing, e.g., on GitHub or StackOverflow.

Home Page:https://reprex.tidyverse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get(".Random.seed") error in empty reprex

DavidLukeThiessen opened this issue · comments

The command get(".Random.seed") works when run interactively in a new R session, but fails when run through reprex() unless the user has done something that affects the random seed.

Example:

reprex::reprex(get(".Random.seed"))

Output:

get(".Random.seed")
#> Error in get(".Random.seed"): object '.Random.seed' not found

Created on 2022-08-26 with reprex v2.0.2

This affects the as.mids() function from the mice package. This expression works when run interactively, but not as a reprex.

mice::as.mids(data.frame(x = c(0, 0),
                         y = c(0, 1),
                         .imp = c(0, 1)))
#> Error in get(".Random.seed", envir = globalenv(), mode = "integer", inherits = FALSE): object '.Random.seed' of mode 'integer' was not found

I would consider this a bug in the mice package.

If I put the code above in a .R file, you can't even source() it.

~/rrr/readr % Rscript -e 'source("~/tmp/mice-reprex.R")'
Error in get(".Random.seed", envir = globalenv(), mode = "integer", inherits = FALSE) : 
  object '.Random.seed' of mode 'integer' was not found
Calls: source ... withVisible -> eval -> eval -> <Anonymous> -> mice -> get
Execution halted