Vscode-r: Preview Environment R code failed on Sys.time() objects

Created on 8 Jul 2019  路  3Comments  路  Source: Ikuyadeu/vscode-R

How to reproduce:

time <- Sys.time()

Then R: Preview Environment

Reason: class(get("time")) gives a vector of string with 2 elements

Too lazy to submit a pull-request; a quick fix on dist.js works for me.
Fix:
Change

write.csv(data.frame(name=ls(),class=sapply(ls(), function(x) {class(get(x))})...

to

write.csv(data.frame(name=ls(),class=sapply(ls(), function(x) {class(get(x))[1]})...

Most helpful comment

Hi @krzysztofarendt, thanks for your comment. I did think about showing all the classes but in the end went with the same approach as RStudio.

Nice catch on shadowing x! I completely missed that. I think it should be possible to use the pos or envir arguments of get so that it doesn鈥檛 shadow any variables.

@Ikuyadeu Please wait until I fix this before releasing the new version. Thanks!

All 3 comments

@JimmyZJX Thank you for identifying this and for providing a solution! I can do a PR for this.

@andycraig, with this solution some of the class names are lost. Another solution would be to list all of them in a single string:

write.csv(data.frame(name=ls(),class=sapply(ls(), function(.x) {paste(class(get(.x)), collapse = " ")})

Also, .x might be better than x as it is less likely to be used in the actual code. Otherwise any variable named x will be masked by this function and the content will be incorrect.

Hi @krzysztofarendt, thanks for your comment. I did think about showing all the classes but in the end went with the same approach as RStudio.

Nice catch on shadowing x! I completely missed that. I think it should be possible to use the pos or envir arguments of get so that it doesn鈥檛 shadow any variables.

@Ikuyadeu Please wait until I fix this before releasing the new version. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Victsz picture Victsz  路  5Comments

maxheld83 picture maxheld83  路  4Comments

Kalaschnik picture Kalaschnik  路  4Comments

bdeshon picture bdeshon  路  3Comments

michaelHL picture michaelHL  路  3Comments