Possible bug in `class<-` when a class-specific '[[.' method is defined

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible bug in `class<-` when a class-specific '[[.' method is defined

Ghiggi Gionata
Hi all !

I noticed a strange behaviour of the function `class<-` when a class-specific '[[.' method is defined.

Here below a reproducible example :


#-------------------------------------------------------------------.

counttt <- 0

`[[.MYCLASS` = function(x, ...) {
  counttt <<- counttt + 1
  # browser()
  x = NextMethod()
  return(x)
}

df <- as.data.frame(matrix(1:20, nrow=5))
class(df) <- c("MYCLASS","data.frame")
counttt

# The same occurs when using structure(, class=) or attr(,"class")<-
df <- as.data.frame(matrix(1:20, nrow=5))
df <- structure(df, class=c("MYCLASS","data.frame"))
attr(df, "class") <- c("MYCLASS","data.frame")

#-------------------------------------------------------------------.

Why in this example `class<-` is calling  `[[.MYCLASS` 9 times ?

Is there a way to avoid `class<-` to call `[[.MYCLASS` ?


Thank you in advance for your help and suggestions.

Gionata



        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in `class<-` when a class-specific '[[.' method is defined

R devel mailing list
I'm unable to reproduce this with R 3.6.1. Which version are you
using? Is this a fresh session?

On Mon, Jul 15, 2019 at 3:25 AM Ghiggi Gionata <[hidden email]> wrote:

>
> Hi all !
>
> I noticed a strange behaviour of the function `class<-` when a class-specific '[[.' method is defined.
>
> Here below a reproducible example :
>
>
> #-------------------------------------------------------------------.
>
> counttt <- 0
>
> `[[.MYCLASS` = function(x, ...) {
>   counttt <<- counttt + 1
>   # browser()
>   x = NextMethod()
>   return(x)
> }
>
> df <- as.data.frame(matrix(1:20, nrow=5))
> class(df) <- c("MYCLASS","data.frame")
> counttt
>
> # The same occurs when using structure(, class=) or attr(,"class")<-
> df <- as.data.frame(matrix(1:20, nrow=5))
> df <- structure(df, class=c("MYCLASS","data.frame"))
> attr(df, "class") <- c("MYCLASS","data.frame")
>
> #-------------------------------------------------------------------.
>
> Why in this example `class<-` is calling  `[[.MYCLASS` 9 times ?
>
> Is there a way to avoid `class<-` to call `[[.MYCLASS` ?
>
>
> Thank you in advance for your help and suggestions.
>
> Gionata
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



--
Michael Lawrence
Scientist, Bioinformatics and Computational Biology
Genentech, A Member of the Roche Group
Office +1 (650) 225-7760
[hidden email]

Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in `class<-` when a class-specific '[[.' method is defined

Duncan Murdoch-2
In reply to this post by Ghiggi Gionata
On 07/07/2019 11:49 a.m., Ghiggi Gionata wrote:

> Hi all !
>
> I noticed a strange behaviour of the function `class<-` when a class-specific '[[.' method is defined.
>
> Here below a reproducible example :
>
>
> #-------------------------------------------------------------------.
>
> counttt <- 0
>
> `[[.MYCLASS` = function(x, ...) {
>    counttt <<- counttt + 1
>    # browser()
>    x = NextMethod()
>    return(x)
> }
>
> df <- as.data.frame(matrix(1:20, nrow=5))
> class(df) <- c("MYCLASS","data.frame")
> counttt
>
> # The same occurs when using structure(, class=) or attr(,"class")<-
> df <- as.data.frame(matrix(1:20, nrow=5))
> df <- structure(df, class=c("MYCLASS","data.frame"))
> attr(df, "class") <- c("MYCLASS","data.frame")
>
> #-------------------------------------------------------------------.
>
> Why in this example `class<-` is calling  `[[.MYCLASS` 9 times ?
>
> Is there a way to avoid `class<-` to call `[[.MYCLASS` ?
>
>
> Thank you in advance for your help and suggestions.

This is what I see:


 > counttt <- 0
 >
 > `[[.MYCLASS` = function(x, ...) {
+   counttt <<- counttt + 1
+   # browser()
+   x = NextMethod()
+   return(x)
+ }
 >
 > df <- as.data.frame(matrix(1:20, nrow=5))
 > class(df) <- c("MYCLASS","data.frame")
 > counttt
[1] 0

So there's something else going on in your system.  Maybe post
sessionInfo()?

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in `class<-` when a class-specific '[[.' method is defined

Rui Barradas
Hello,

Clean R 3.6.1 session on Ubuntu 19.04, RStudio 1.1.453. sessionInfo() at
the end.

I can reproduce this.

counttt <- 0

`[[.MYCLASS` = function(x, ...) {
   counttt <<- counttt + 1
   # browser()
   x = NextMethod()
   return(x)
}

df <- as.data.frame(matrix(1:20, nrow=5))
class(df) <- c("MYCLASS","data.frame")
counttt
#[1] 9


But there's more. I tried to print the values of x in the method and got
really strange results

counttt <- 0

`[[.MYCLASS` = function(x, ...) {
   counttt <<- counttt + 1
   print(x)
   # browser()
   x = NextMethod()
   return(x)
}

df <- as.data.frame(matrix(1:20, nrow=5))
class(df) <- c("MYCLASS","data.frame")
counttt
#[1] 151


If I change print to print.data.frame it goes up to

counttt
#[1] 176

With print.default back to 9. What is the print method called in the
second example?


sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 19.04

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0

locale:
  [1] LC_CTYPE=pt_PT.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=pt_PT.UTF-8        LC_COLLATE=pt_PT.UTF-8
  [5] LC_MONETARY=pt_PT.UTF-8    LC_MESSAGES=pt_PT.UTF-8
  [7] LC_PAPER=pt_PT.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=pt_PT.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods
[7] base

loaded via a namespace (and not attached):
   [1] sos_2.0-0           nlme_3.1-140        matrixStats_0.54.0
   [4] fs_1.2.7            xts_0.11-2          usethis_1.5.0
   [7] lubridate_1.7.4     devtools_2.0.2      RColorBrewer_1.1-2
  [10] rprojroot_1.3-2     rbenchmark_1.0.0    tools_3.6.1
  [13] backports_1.1.4     R6_2.4.0            rpart_4.1-15
  [16] Hmisc_4.2-0         lazyeval_0.2.2      colorspace_1.4-1
  [19] nnet_7.3-12         npsurv_0.4-0        withr_2.1.2
  [22] tidyselect_0.2.5    gridExtra_2.3       prettyunits_1.0.2
  [25] processx_3.3.0      curl_3.3            compiler_3.6.1
  [28] cli_1.1.0           htmlTable_1.13.1    randomNames_1.4-0.0
  [31] dvmisc_1.1.3        desc_1.2.0          tseries_0.10-46
  [34] scales_1.0.0        checkmate_1.9.1     lmtest_0.9-36
  [37] fracdiff_1.4-2      mvtnorm_1.0-10      quadprog_1.5-6
  [40] callr_3.2.0         stringr_1.4.0       digest_0.6.18
  [43] foreign_0.8-71      rio_0.5.16          base64enc_0.1-3
  [46] stocks_1.1.4        pkgconfig_2.0.2     htmltools_0.3.6
  [49] sessioninfo_1.1.1   readxl_1.3.1        htmlwidgets_1.3
  [52] rlang_0.3.4         TTR_0.23-4          rstudioapi_0.10
  [55] quantmod_0.4-14     MLmetrics_1.1.1     zoo_1.8-5
  [58] zip_2.0.1           acepack_1.4.1       dplyr_0.8.0.1
  [61] car_3.0-2           magrittr_1.5        Formula_1.2-3
  [64] Matrix_1.2-17       Rcpp_1.0.1          munsell_0.5.0
  [67] abind_1.4-5         stringi_1.4.3       forecast_8.6
  [70] yaml_2.2.0          carData_3.0-2       MASS_7.3-51.3
  [73] pkgbuild_1.0.3      plyr_1.8.4          grid_3.6.1
  [76] parallel_3.6.1      forcats_0.4.0       crayon_1.3.4
  [79] lattice_0.20-38     haven_2.1.0         splines_3.6.1
  [82] hms_0.4.2           knitr_1.22          ps_1.3.0
  [85] pillar_1.4.0        pkgload_1.0.2       urca_1.3-0
  [88] glue_1.3.1          lsei_1.2-0          babynames_1.0.0
  [91] latticeExtra_0.6-28 data.table_1.12.2   remotes_2.0.4
  [94] cellranger_1.1.0    testthat_2.1.0      gtable_0.3.0
  [97] purrr_0.3.2         assertthat_0.2.1    ggplot2_3.1.1
[100] openxlsx_4.1.0      xfun_0.6            survey_3.35-1
[103] survival_2.44-1.1   timeDate_3043.102   tibble_2.1.1
[106] memoise_1.1.0       cluster_2.0.8       toOrdinal_1.1-0.0
[109] fitdistrplus_1.0-14 brew_1.0-6



Hope this helps,

Rui Barradas


Às 13:16 de 15/07/19, Duncan Murdoch escreveu:

> On 07/07/2019 11:49 a.m., Ghiggi Gionata wrote:
>> Hi all !
>>
>> I noticed a strange behaviour of the function `class<-` when a
>> class-specific '[[.' method is defined.
>>
>> Here below a reproducible example :
>>
>>
>> #-------------------------------------------------------------------.
>>
>> counttt <- 0
>>
>> `[[.MYCLASS` = function(x, ...) {
>>    counttt <<- counttt + 1
>>    # browser()
>>    x = NextMethod()
>>    return(x)
>> }
>>
>> df <- as.data.frame(matrix(1:20, nrow=5))
>> class(df) <- c("MYCLASS","data.frame")
>> counttt
>>
>> # The same occurs when using structure(, class=) or attr(,"class")<-
>> df <- as.data.frame(matrix(1:20, nrow=5))
>> df <- structure(df, class=c("MYCLASS","data.frame"))
>> attr(df, "class") <- c("MYCLASS","data.frame")
>>
>> #-------------------------------------------------------------------.
>>
>> Why in this example `class<-` is calling  `[[.MYCLASS` 9 times ?
>>
>> Is there a way to avoid `class<-` to call `[[.MYCLASS` ?
>>
>>
>> Thank you in advance for your help and suggestions.
>
> This is what I see:
>
>
>  > counttt <- 0
>  >
>  > `[[.MYCLASS` = function(x, ...) {
> +   counttt <<- counttt + 1
> +   # browser()
> +   x = NextMethod()
> +   return(x)
> + }
>  >
>  > df <- as.data.frame(matrix(1:20, nrow=5))
>  > class(df) <- c("MYCLASS","data.frame")
>  > counttt
> [1] 0
>
> So there's something else going on in your system.  Maybe post
> sessionInfo()?
>
> Duncan Murdoch
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: Possible bug in `class<-` when a class-specific '[[.' method is defined

Tierney, Luke
Pasting the entire example into RStudio and hitting return to evaluate
does not show this. Evaluating the finall line to print counttt
separately does.

Looks like RStudio is calling `[[` on your object when examining the
environment for the Environment panel. If this concerns you then you
should contact RStudio.

Best,

luke

On Mon, 15 Jul 2019, Rui Barradas wrote:

> Hello,
>
> Clean R 3.6.1 session on Ubuntu 19.04, RStudio 1.1.453. sessionInfo() at the
> end.
>
> I can reproduce this.
>
> counttt <- 0
>
> `[[.MYCLASS` = function(x, ...) {
>  counttt <<- counttt + 1
>  # browser()
>  x = NextMethod()
>  return(x)
> }
>
> df <- as.data.frame(matrix(1:20, nrow=5))
> class(df) <- c("MYCLASS","data.frame")
> counttt
> #[1] 9
>
>
> But there's more. I tried to print the values of x in the method and got
> really strange results
>
> counttt <- 0
>
> `[[.MYCLASS` = function(x, ...) {
>  counttt <<- counttt + 1
>  print(x)
>  # browser()
>  x = NextMethod()
>  return(x)
> }
>
> df <- as.data.frame(matrix(1:20, nrow=5))
> class(df) <- c("MYCLASS","data.frame")
> counttt
> #[1] 151
>
>
> If I change print to print.data.frame it goes up to
>
> counttt
> #[1] 176
>
> With print.default back to 9. What is the print method called in the second
> example?
>
>
> sessionInfo()
> R version 3.6.1 (2019-07-05)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Ubuntu 19.04
>
> Matrix products: default
> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0
>
> locale:
> [1] LC_CTYPE=pt_PT.UTF-8       LC_NUMERIC=C
> [3] LC_TIME=pt_PT.UTF-8        LC_COLLATE=pt_PT.UTF-8
> [5] LC_MONETARY=pt_PT.UTF-8    LC_MESSAGES=pt_PT.UTF-8
> [7] LC_PAPER=pt_PT.UTF-8       LC_NAME=C
> [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=pt_PT.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods
> [7] base
>
> loaded via a namespace (and not attached):
>  [1] sos_2.0-0           nlme_3.1-140        matrixStats_0.54.0
>  [4] fs_1.2.7            xts_0.11-2          usethis_1.5.0
>  [7] lubridate_1.7.4     devtools_2.0.2      RColorBrewer_1.1-2
> [10] rprojroot_1.3-2     rbenchmark_1.0.0    tools_3.6.1
> [13] backports_1.1.4     R6_2.4.0            rpart_4.1-15
> [16] Hmisc_4.2-0         lazyeval_0.2.2      colorspace_1.4-1
> [19] nnet_7.3-12         npsurv_0.4-0        withr_2.1.2
> [22] tidyselect_0.2.5    gridExtra_2.3       prettyunits_1.0.2
> [25] processx_3.3.0      curl_3.3            compiler_3.6.1
> [28] cli_1.1.0           htmlTable_1.13.1    randomNames_1.4-0.0
> [31] dvmisc_1.1.3        desc_1.2.0          tseries_0.10-46
> [34] scales_1.0.0        checkmate_1.9.1     lmtest_0.9-36
> [37] fracdiff_1.4-2      mvtnorm_1.0-10      quadprog_1.5-6
> [40] callr_3.2.0         stringr_1.4.0       digest_0.6.18
> [43] foreign_0.8-71      rio_0.5.16          base64enc_0.1-3
> [46] stocks_1.1.4        pkgconfig_2.0.2     htmltools_0.3.6
> [49] sessioninfo_1.1.1   readxl_1.3.1        htmlwidgets_1.3
> [52] rlang_0.3.4         TTR_0.23-4          rstudioapi_0.10
> [55] quantmod_0.4-14     MLmetrics_1.1.1     zoo_1.8-5
> [58] zip_2.0.1           acepack_1.4.1       dplyr_0.8.0.1
> [61] car_3.0-2           magrittr_1.5        Formula_1.2-3
> [64] Matrix_1.2-17       Rcpp_1.0.1          munsell_0.5.0
> [67] abind_1.4-5         stringi_1.4.3       forecast_8.6
> [70] yaml_2.2.0          carData_3.0-2       MASS_7.3-51.3
> [73] pkgbuild_1.0.3      plyr_1.8.4          grid_3.6.1
> [76] parallel_3.6.1      forcats_0.4.0       crayon_1.3.4
> [79] lattice_0.20-38     haven_2.1.0         splines_3.6.1
> [82] hms_0.4.2           knitr_1.22          ps_1.3.0
> [85] pillar_1.4.0        pkgload_1.0.2       urca_1.3-0
> [88] glue_1.3.1          lsei_1.2-0          babynames_1.0.0
> [91] latticeExtra_0.6-28 data.table_1.12.2   remotes_2.0.4
> [94] cellranger_1.1.0    testthat_2.1.0      gtable_0.3.0
> [97] purrr_0.3.2         assertthat_0.2.1    ggplot2_3.1.1
> [100] openxlsx_4.1.0      xfun_0.6            survey_3.35-1
> [103] survival_2.44-1.1   timeDate_3043.102   tibble_2.1.1
> [106] memoise_1.1.0       cluster_2.0.8       toOrdinal_1.1-0.0
> [109] fitdistrplus_1.0-14 brew_1.0-6
>
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Às 13:16 de 15/07/19, Duncan Murdoch escreveu:
>> On 07/07/2019 11:49 a.m., Ghiggi Gionata wrote:
>>> Hi all !
>>>
>>> I noticed a strange behaviour of the function `class<-` when a
>>> class-specific '[[.' method is defined.
>>>
>>> Here below a reproducible example :
>>>
>>>
>>> #-------------------------------------------------------------------.
>>>
>>> counttt <- 0
>>>
>>> `[[.MYCLASS` = function(x, ...) {
>>>    counttt <<- counttt + 1
>>>    # browser()
>>>    x = NextMethod()
>>>    return(x)
>>> }
>>>
>>> df <- as.data.frame(matrix(1:20, nrow=5))
>>> class(df) <- c("MYCLASS","data.frame")
>>> counttt
>>>
>>> # The same occurs when using structure(, class=) or attr(,"class")<-
>>> df <- as.data.frame(matrix(1:20, nrow=5))
>>> df <- structure(df, class=c("MYCLASS","data.frame"))
>>> attr(df, "class") <- c("MYCLASS","data.frame")
>>>
>>> #-------------------------------------------------------------------.
>>>
>>> Why in this example `class<-` is calling  `[[.MYCLASS` 9 times ?
>>>
>>> Is there a way to avoid `class<-` to call `[[.MYCLASS` ?
>>>
>>>
>>> Thank you in advance for your help and suggestions.
>>
>> This is what I see:
>>
>>
>>  > counttt <- 0
>>  >
>>  > `[[.MYCLASS` = function(x, ...) {
>> +   counttt <<- counttt + 1
>> +   # browser()
>> +   x = NextMethod()
>> +   return(x)
>> + }
>>  >
>>  > df <- as.data.frame(matrix(1:20, nrow=5))
>>  > class(df) <- c("MYCLASS","data.frame")
>>  > counttt
>> [1] 0
>>
>> So there's something else going on in your system.  Maybe post
>> sessionInfo()?
>>
>> Duncan Murdoch
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in `class<-` when a class-specific '[[.' method is defined

Duncan Murdoch-2
In reply to this post by Rui Barradas
On 15/07/2019 8:57 a.m., Rui Barradas wrote:
> Hello,
>
> Clean R 3.6.1 session on Ubuntu 19.04, RStudio 1.1.453. sessionInfo() at
> the end.

That's not what I'd call a "clean session" with all those packages loaded:

> loaded via a namespace (and not attached):
>     [1] sos_2.0-0           nlme_3.1-140        matrixStats_0.54.0
>     [4] fs_1.2.7            xts_0.11-2          usethis_1.5.0
>     [7] lubridate_1.7.4     devtools_2.0.2      RColorBrewer_1.1-2
>    [10] rprojroot_1.3-2     rbenchmark_1.0.0    tools_3.6.1
>    [13] backports_1.1.4     R6_2.4.0            rpart_4.1-15
>    [16] Hmisc_4.2-0         lazyeval_0.2.2      colorspace_1.4-1
>    [19] nnet_7.3-12         npsurv_0.4-0        withr_2.1.2
>    [22] tidyselect_0.2.5    gridExtra_2.3       prettyunits_1.0.2
>    [25] processx_3.3.0      curl_3.3            compiler_3.6.1
>    [28] cli_1.1.0           htmlTable_1.13.1    randomNames_1.4-0.0
>    [31] dvmisc_1.1.3        desc_1.2.0          tseries_0.10-46
>    [34] scales_1.0.0        checkmate_1.9.1     lmtest_0.9-36
>    [37] fracdiff_1.4-2      mvtnorm_1.0-10      quadprog_1.5-6
>    [40] callr_3.2.0         stringr_1.4.0       digest_0.6.18
>    [43] foreign_0.8-71      rio_0.5.16          base64enc_0.1-3
>    [46] stocks_1.1.4        pkgconfig_2.0.2     htmltools_0.3.6
>    [49] sessioninfo_1.1.1   readxl_1.3.1        htmlwidgets_1.3
>    [52] rlang_0.3.4         TTR_0.23-4          rstudioapi_0.10
>    [55] quantmod_0.4-14     MLmetrics_1.1.1     zoo_1.8-5
>    [58] zip_2.0.1           acepack_1.4.1       dplyr_0.8.0.1
>    [61] car_3.0-2           magrittr_1.5        Formula_1.2-3
>    [64] Matrix_1.2-17       Rcpp_1.0.1          munsell_0.5.0
>    [67] abind_1.4-5         stringi_1.4.3       forecast_8.6
>    [70] yaml_2.2.0          carData_3.0-2       MASS_7.3-51.3
>    [73] pkgbuild_1.0.3      plyr_1.8.4          grid_3.6.1
>    [76] parallel_3.6.1      forcats_0.4.0       crayon_1.3.4
>    [79] lattice_0.20-38     haven_2.1.0         splines_3.6.1
>    [82] hms_0.4.2           knitr_1.22          ps_1.3.0
>    [85] pillar_1.4.0        pkgload_1.0.2       urca_1.3-0
>    [88] glue_1.3.1          lsei_1.2-0          babynames_1.0.0
>    [91] latticeExtra_0.6-28 data.table_1.12.2   remotes_2.0.4
>    [94] cellranger_1.1.0    testthat_2.1.0      gtable_0.3.0
>    [97] purrr_0.3.2         assertthat_0.2.1    ggplot2_3.1.1
> [100] openxlsx_4.1.0      xfun_0.6            survey_3.35-1
> [103] survival_2.44-1.1   timeDate_3043.102   tibble_2.1.1
> [106] memoise_1.1.0       cluster_2.0.8       toOrdinal_1.1-0.0
> [109] fitdistrplus_1.0-14 brew_1.0-6
>
>

However, even when I load almost all of those, I don't see the problem.
I've got the same R version, and a newer Rstudio version (mine is
1.2.1335 on a Mac).  I couldn't load ] "latticeExtradata.table" and
"fitdistrplusbrew", and I didn't check my package versions against yours.

I'd suspect the issue is with RStudio somehow, because it needs to do a
lot to maintain its environment view.  Do you see this when running R
from the command line?

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: Possible bug in `class<-` when a class-specific '[[.' method is defined

Duncan Murdoch-2
In reply to this post by Tierney, Luke
On 15/07/2019 9:24 a.m., Tierney, Luke wrote:
> Pasting the entire example into RStudio and hitting return to evaluate
> does not show this. Evaluating the finall line to print counttt
> separately does.
>
> Looks like RStudio is calling `[[` on your object when examining the
> environment for the Environment panel. If this concerns you then you
> should contact RStudio.

Now I see it!

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in `class<-` when a class-specific '[[.' method is defined

Rui Barradas
In reply to this post by Duncan Murdoch-2
Hello,

Inline.

Às 14:26 de 15/07/19, Duncan Murdoch escreveu:
> On 15/07/2019 8:57 a.m., Rui Barradas wrote:
>> Hello,
>>
>> Clean R 3.6.1 session on Ubuntu 19.04, RStudio 1.1.453. sessionInfo() at
>> the end.
>
> That's not what I'd call a "clean session" with all those packages loaded:

You are right, but when I wrote that it *was* clean. Then, for some
reason I don't understand, RStudio loaded them all. Guess I'll have to
check what is going on here.

>
>> loaded via a namespace (and not attached):
>>     [1] sos_2.0-0           nlme_3.1-140        matrixStats_0.54.0
>>     [4] fs_1.2.7            xts_0.11-2          usethis_1.5.0
>>     [7] lubridate_1.7.4     devtools_2.0.2      RColorBrewer_1.1-2
>>    [10] rprojroot_1.3-2     rbenchmark_1.0.0    tools_3.6.1
>>    [13] backports_1.1.4     R6_2.4.0            rpart_4.1-15
>>    [16] Hmisc_4.2-0         lazyeval_0.2.2      colorspace_1.4-1
>>    [19] nnet_7.3-12         npsurv_0.4-0        withr_2.1.2
>>    [22] tidyselect_0.2.5    gridExtra_2.3       prettyunits_1.0.2
>>    [25] processx_3.3.0      curl_3.3            compiler_3.6.1
>>    [28] cli_1.1.0           htmlTable_1.13.1    randomNames_1.4-0.0
>>    [31] dvmisc_1.1.3        desc_1.2.0          tseries_0.10-46
>>    [34] scales_1.0.0        checkmate_1.9.1     lmtest_0.9-36
>>    [37] fracdiff_1.4-2      mvtnorm_1.0-10      quadprog_1.5-6
>>    [40] callr_3.2.0         stringr_1.4.0       digest_0.6.18
>>    [43] foreign_0.8-71      rio_0.5.16          base64enc_0.1-3
>>    [46] stocks_1.1.4        pkgconfig_2.0.2     htmltools_0.3.6
>>    [49] sessioninfo_1.1.1   readxl_1.3.1        htmlwidgets_1.3
>>    [52] rlang_0.3.4         TTR_0.23-4          rstudioapi_0.10
>>    [55] quantmod_0.4-14     MLmetrics_1.1.1     zoo_1.8-5
>>    [58] zip_2.0.1           acepack_1.4.1       dplyr_0.8.0.1
>>    [61] car_3.0-2           magrittr_1.5        Formula_1.2-3
>>    [64] Matrix_1.2-17       Rcpp_1.0.1          munsell_0.5.0
>>    [67] abind_1.4-5         stringi_1.4.3       forecast_8.6
>>    [70] yaml_2.2.0          carData_3.0-2       MASS_7.3-51.3
>>    [73] pkgbuild_1.0.3      plyr_1.8.4          grid_3.6.1
>>    [76] parallel_3.6.1      forcats_0.4.0       crayon_1.3.4
>>    [79] lattice_0.20-38     haven_2.1.0         splines_3.6.1
>>    [82] hms_0.4.2           knitr_1.22          ps_1.3.0
>>    [85] pillar_1.4.0        pkgload_1.0.2       urca_1.3-0
>>    [88] glue_1.3.1          lsei_1.2-0          babynames_1.0.0
>>    [91] latticeExtra_0.6-28 data.table_1.12.2   remotes_2.0.4
>>    [94] cellranger_1.1.0    testthat_2.1.0      gtable_0.3.0
>>    [97] purrr_0.3.2         assertthat_0.2.1    ggplot2_3.1.1
>> [100] openxlsx_4.1.0      xfun_0.6            survey_3.35-1
>> [103] survival_2.44-1.1   timeDate_3043.102   tibble_2.1.1
>> [106] memoise_1.1.0       cluster_2.0.8       toOrdinal_1.1-0.0
>> [109] fitdistrplus_1.0-14 brew_1.0-6
>>
>>
>
> However, even when I load almost all of those, I don't see the problem.
> I've got the same R version, and a newer Rstudio version (mine is
> 1.2.1335 on a Mac).  I couldn't load ] "latticeExtradata.table" and
> "fitdistrplusbrew", and I didn't check my package versions against yours.
>
> I'd suspect the issue is with RStudio somehow, because it needs to do a
> lot to maintain its environment view.  Do you see this when running R
> from the command line?
>
> Duncan Murdoch
>

It's a RStudio thing.
Tested with

Rscript --vanilla test.R


the result is the expected one.
(test.R has the obvious contents.)


Rui Barradas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in `class<-` when a class-specific '[[.' method is defined

Kevin Ushey
When RStudio builds the Environment pane, it will evaluate some R code
on objects in your global environment (as you have seen). In
particular, for better or worse, it calls `str()` on objects in the
global environment, to get a short text summary of the object.

So, to reproduce what you're seeing in a plain R session, you can check:

> counttt
[1] 0
> str(df)
Classes 'MYCLASS' and 'data.frame':     5 obs. of  4 variables:
 $ V1: int  1 2 3 4 5
 $ V2: int  6 7 8 9 10
 $ V3: int  11 12 13 14 15
 $ V4: int  16 17 18 19 20
> counttt
[1] 9

Newer versions will allow you to disable the Environment pane if you
so desire, since calling `str()` can have these kinds of undesirable
side effects in some cases.

In general though, if you're reporting a bug in R (as opposed to
RStudio) it's best to verify that you can reproduce the issue in a
'plain' R session (e.g. in the terminal) to be absolutely sure you're
seeing an R issue as opposed to an RStudio issue, as I imagine the
last thing R Core wants to do is spend time tracking down an issue
only to find it was in RStudio rather than R itself...

If you want to follow up further with the RStudio team I'd recommend
making a post at https://community.rstudio.com/c/rstudio-ide.

Thanks,
Kevin

On Mon, Jul 15, 2019 at 7:59 AM Rui Barradas <[hidden email]> wrote:

>
> Hello,
>
> Inline.
>
> Às 14:26 de 15/07/19, Duncan Murdoch escreveu:
> > On 15/07/2019 8:57 a.m., Rui Barradas wrote:
> >> Hello,
> >>
> >> Clean R 3.6.1 session on Ubuntu 19.04, RStudio 1.1.453. sessionInfo() at
> >> the end.
> >
> > That's not what I'd call a "clean session" with all those packages loaded:
>
> You are right, but when I wrote that it *was* clean. Then, for some
> reason I don't understand, RStudio loaded them all. Guess I'll have to
> check what is going on here.
>
> >
> >> loaded via a namespace (and not attached):
> >>     [1] sos_2.0-0           nlme_3.1-140        matrixStats_0.54.0
> >>     [4] fs_1.2.7            xts_0.11-2          usethis_1.5.0
> >>     [7] lubridate_1.7.4     devtools_2.0.2      RColorBrewer_1.1-2
> >>    [10] rprojroot_1.3-2     rbenchmark_1.0.0    tools_3.6.1
> >>    [13] backports_1.1.4     R6_2.4.0            rpart_4.1-15
> >>    [16] Hmisc_4.2-0         lazyeval_0.2.2      colorspace_1.4-1
> >>    [19] nnet_7.3-12         npsurv_0.4-0        withr_2.1.2
> >>    [22] tidyselect_0.2.5    gridExtra_2.3       prettyunits_1.0.2
> >>    [25] processx_3.3.0      curl_3.3            compiler_3.6.1
> >>    [28] cli_1.1.0           htmlTable_1.13.1    randomNames_1.4-0.0
> >>    [31] dvmisc_1.1.3        desc_1.2.0          tseries_0.10-46
> >>    [34] scales_1.0.0        checkmate_1.9.1     lmtest_0.9-36
> >>    [37] fracdiff_1.4-2      mvtnorm_1.0-10      quadprog_1.5-6
> >>    [40] callr_3.2.0         stringr_1.4.0       digest_0.6.18
> >>    [43] foreign_0.8-71      rio_0.5.16          base64enc_0.1-3
> >>    [46] stocks_1.1.4        pkgconfig_2.0.2     htmltools_0.3.6
> >>    [49] sessioninfo_1.1.1   readxl_1.3.1        htmlwidgets_1.3
> >>    [52] rlang_0.3.4         TTR_0.23-4          rstudioapi_0.10
> >>    [55] quantmod_0.4-14     MLmetrics_1.1.1     zoo_1.8-5
> >>    [58] zip_2.0.1           acepack_1.4.1       dplyr_0.8.0.1
> >>    [61] car_3.0-2           magrittr_1.5        Formula_1.2-3
> >>    [64] Matrix_1.2-17       Rcpp_1.0.1          munsell_0.5.0
> >>    [67] abind_1.4-5         stringi_1.4.3       forecast_8.6
> >>    [70] yaml_2.2.0          carData_3.0-2       MASS_7.3-51.3
> >>    [73] pkgbuild_1.0.3      plyr_1.8.4          grid_3.6.1
> >>    [76] parallel_3.6.1      forcats_0.4.0       crayon_1.3.4
> >>    [79] lattice_0.20-38     haven_2.1.0         splines_3.6.1
> >>    [82] hms_0.4.2           knitr_1.22          ps_1.3.0
> >>    [85] pillar_1.4.0        pkgload_1.0.2       urca_1.3-0
> >>    [88] glue_1.3.1          lsei_1.2-0          babynames_1.0.0
> >>    [91] latticeExtra_0.6-28 data.table_1.12.2   remotes_2.0.4
> >>    [94] cellranger_1.1.0    testthat_2.1.0      gtable_0.3.0
> >>    [97] purrr_0.3.2         assertthat_0.2.1    ggplot2_3.1.1
> >> [100] openxlsx_4.1.0      xfun_0.6            survey_3.35-1
> >> [103] survival_2.44-1.1   timeDate_3043.102   tibble_2.1.1
> >> [106] memoise_1.1.0       cluster_2.0.8       toOrdinal_1.1-0.0
> >> [109] fitdistrplus_1.0-14 brew_1.0-6
> >>
> >>
> >
> > However, even when I load almost all of those, I don't see the problem.
> > I've got the same R version, and a newer Rstudio version (mine is
> > 1.2.1335 on a Mac).  I couldn't load ] "latticeExtradata.table" and
> > "fitdistrplusbrew", and I didn't check my package versions against yours.
> >
> > I'd suspect the issue is with RStudio somehow, because it needs to do a
> > lot to maintain its environment view.  Do you see this when running R
> > from the command line?
> >
> > Duncan Murdoch
> >
>
> It's a RStudio thing.
> Tested with
>
> Rscript --vanilla test.R
>
>
> the result is the expected one.
> (test.R has the obvious contents.)
>
>
> Rui Barradas
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel