[Rd] Result of 'seq' doesn't use compact internal representation

Duncan Murdoch murdoch.duncan at gmail.com
Sun Apr 29 13:22:53 CEST 2018


On 28/04/2018 11:11 PM, Suharto Anggono Suharto Anggono via R-devel wrote:
>> .Internal(inspect(1:10))
> @300e4e8 13 INTSXP g0c0 [NAM(3)]  1 : 10 (compact)
>> .Internal(inspect(seq(1,10)))
> @3b6e1f8 13 INTSXP g0c4 [] (len=10, tl=0) 1,2,3,4,5,...
>> system.time(1:1e7)
>     user  system elapsed
>        0       0       0
>> system.time(seq(1,1e7))
>     user  system elapsed
>     0.05    0.00    0.04
> 
> It seems that result of function 'seq' doesn't use compact internal representation. However, looking at the code of function 'seq.default', seq(1,n) produces 1:n. What is going on?

It looks like it is related to using compiled or interpreted code:

 > library(gtools)
 > seq2 <- unByteCode(seq.default)
 > .Internal(inspect(seq.default(1,10)))
@7fa53847dcd8 13 INTSXP g0c4 [] (len=10, tl=0) 1,2,3,4,5,...
 > .Internal(inspect(seq2(1,10)))
@7fa537fa0bf0 13 INTSXP g0c0 [NAM(3)]  1 : 10 (compact)

Duncan Murdoch

> 
>> h <- seq.default
>> environment(h) <- .GlobalEnv
>> library(compiler)
>> enableJIT(0)
> [1] 3
>> .Internal(inspect(h(1,10)))
> @375ade8 13 INTSXP g0c0 [NAM(3)]  1 : 10 (compact)
> 
> A non-byte-compiled version of function 'seq.default' can produce object that uses compact internal representation.
> 
> 
>> sessionInfo()
> R version 3.5.0 (2018-04-23)
> Platform: i386-w64-mingw32/i386 (32-bit)
> Running under: Windows XP (build 2600) Service Pack 3
> 
> Matrix products: default
> 
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
> 
> attached base packages:
> [1] compiler  stats     graphics  grDevices utils     datasets  methods
> [8] base
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list