32  Classes and OOP

Object-Oriented Programming (OOP) is a programming paradigm built around objects with associated data, known as attributes, and functions, known as methods.

There are 4 main class systems in R:

S3 and S4 methods are part of generic functions. RC and R6 methods are part of the object, but you can (and should) write generic functions for them as well.

This chapter will focus on the ubiquitous S3 system. For more advanced, and real OOP applications, we recommend looking into the R6 system.

32.1 S3

Most R objects we have been using so far are S3 objects. Data frames are some of the most common S3 objects.

Generic functions are functions that act differently based on the class of the input object. We have already used many of them. For example, summary() works differently on a data.frame, on a factor, or a glm object, etc.

Generic functions in R are saved as functionname.classname() and called automatically, based on the class of the first argument. This allows the same function, e.g. print(), summary(), c(), to have a different effect on objects of different classes. For example, the print() function applied on a data frame, will automatically call print.data.frame(), while applied on a factor, it will call print.factor().
This means that when you type print(iris) this calls print.data.frame(iris).

Note how the R documentation lists usage information separately for each S3 method, e.g. ## S3 method for class 'factor'.

32.1.1 methods()

To get a list of all available methods defined for a specific class,
i.e. “What functions can I use on this object?”

methods(class = "data.frame")
 [1] [             [[            [[<-          [<-           $<-          
 [6] aggregate     anyDuplicated anyNA         as.data.frame as.list      
[11] as.matrix     as.vector     by            cbind         coerce       
[16] dim           dimnames      dimnames<-    droplevels    duplicated   
[21] edit          format        formula       head          initialize   
[26] is.na         Math          merge         na.exclude    na.omit      
[31] Ops           plot          print         prompt        rbind        
[36] row.names     row.names<-   rowsum        show          slotsFromS3  
[41] sort_by       split         split<-       stack         str          
[46] subset        summary       Summary       t             tail         
[51] transform     type.convert  unique        unstack       within       
[56] xtfrm        
see '?methods' for accessing help and source code

Conversely, to get a list of all available methods for a generic function, i.e. “What objects can I use this function on?”

methods(generic.function = "plot")
 [1] plot.acf*           plot.data.frame*    plot.decomposed.ts*
 [4] plot.default        plot.dendrogram*    plot.density*      
 [7] plot.ecdf           plot.factor*        plot.formula*      
[10] plot.function       plot.hclust*        plot.histogram*    
[13] plot.HoltWinters*   plot.isoreg*        plot.lm*           
[16] plot.medpolish*     plot.mlm*           plot.ppr*          
[19] plot.prcomp*        plot.princomp*      plot.profile*      
[22] plot.profile.nls*   plot.raster*        plot.spec*         
[25] plot.stepfun        plot.stl*           plot.table*        
[28] plot.ts             plot.tskernel*      plot.TukeyHSD*     
see '?methods' for accessing help and source code

32.1.2 Defining custom S3 classes

It very simple to assign an object to a new class.
There is no formal class definition, an object is directly assigned to a class by name. An object can belong to multiple classes:

x <- rnorm(500)
class(x) <- c("specialvector", "numeric")
class(x)
[1] "specialvector" "numeric"      

The hierarchy of classes goes left to right, meaning that generic methods are searched for classes in the order they appear in the output of class().

If we print x, since there is no print method for class specialvector or for numeric, the default print.default() command is automatically called:

  [1]  0.209776267 -1.030360010 -2.683244314 -0.598582029 -1.557680867
  [6]  0.313827842 -0.602322142 -0.271172064  1.401769625  0.861991410
 [11] -0.437413971  1.790902173  0.573493437  1.137190595 -0.072726237
 [16]  0.525097544  1.026344245 -0.614522088  2.065700592 -1.533935221
 [21] -0.001201362 -0.924766045 -1.333183264  1.487372772 -1.714447665
 [26]  0.811101690 -0.326313957 -1.033493055  0.498531452 -0.654595614
 [31] -1.323221932 -0.520260785 -0.057443368  0.014895295  0.186655940
 [36]  1.104104927 -0.108047008  0.638683649 -0.485648108 -0.337503611
 [41]  0.667284319 -0.053608559 -1.036029579 -1.216171862 -0.294195055
 [46]  0.367394626  0.461899033  0.225304085  0.294404233  0.731343123
 [51]  1.109236886 -0.714347429  0.185405829 -0.293406452 -0.237118863
 [56] -0.339854109 -1.539213781  0.542319069 -2.093494310 -0.844003284
 [61] -0.548832516  0.487433059 -1.010726613  0.657532456 -1.003483053
 [66] -1.494312404  0.003772973  0.698674329  1.872362809  0.390708593
 [71]  0.253319807 -1.406966288  0.722706849 -0.404125639 -0.165836101
 [76]  2.028698921 -0.832169885  1.124598629  1.654797508  0.309571227
 [81]  0.484517143  1.480256040  0.708233545 -1.028914904  0.825996652
 [86]  0.101659771  1.359229588 -1.130766061  0.604678258 -0.536529559
 [91]  0.209734902  2.028629382 -0.230618920  0.304106177  0.484951142
 [96] -1.130670260  0.948818902  1.196753795 -0.278766042 -1.611013089
[101]  0.041340196 -0.190446887 -0.076806208  0.321798026  0.409749040
[106]  0.624864732 -0.826982981 -0.134393768  0.703411775 -0.787159813
[111] -1.355966440  0.002857996  0.159362845  0.274773550 -1.959072908
[116] -0.007822947 -2.450454520 -0.222355574 -1.076532401 -0.299867765
[121] -0.816509715 -1.729425250 -1.215465332 -0.890949194  0.560203207
[126]  0.758755579 -1.358278160 -0.168206251  0.103618784  1.433714489
[131]  0.065091750  0.006726355  0.235408409 -0.352468394  0.712583489
[136] -1.264236773  1.286904081  0.827597277 -0.341173449 -0.402096755
[141] -0.419011737 -0.621626159 -0.186335760  1.704104927 -0.761226267
[146] -1.610189864  0.189666989 -1.826535381  0.615925609  0.781805245
[151] -1.544666009 -0.627798535 -1.149868342  1.298677843  1.318264410
[156] -1.385332983 -1.044893595  1.225805658 -0.898068094  1.217606589
[161]  1.767950539  0.048782953 -0.392547450 -1.612495105  1.540648605
[166] -0.802886758  1.379476268 -0.814655587  1.341139174 -0.181589255
[171] -0.214068157  1.756063241 -1.028762110 -1.880676486  0.274561855
[176]  0.454012700 -0.406668993 -0.630236006  1.496869494  0.067495367
[181]  2.767094441  0.990917427  0.832225889 -1.494982600  1.413677254
[186] -1.103304232 -0.465162937  0.183868035 -1.868030103 -0.117628001
[191]  0.622618798 -0.538036205 -0.209250379  1.586558380  0.243156875
[196] -0.157343114 -0.828315058  1.137439046 -0.752721143 -0.994831441
[201] -0.136005325 -0.816332177  0.783621130 -1.283490785 -1.368775376
[206]  1.894014939 -1.021640019  0.530346469 -0.924058879 -1.096467456
[211] -0.035692815 -0.526073443 -1.639758062  0.683840443 -1.017800245
[216] -0.347145587 -0.268729468  0.615028393  0.234242186  0.355570461
[221] -0.931370175 -0.456048706  0.159603005  0.297584151 -0.819127169
[226]  1.814704987 -0.919621772  0.930764506 -1.278293991 -0.201841918
[231] -0.766239862  1.564683127 -0.535781294 -0.079413161 -0.550550756
[236] -0.726147169  0.461158588  0.882758834 -1.524965209 -0.192229621
[241] -0.804709667  0.404939063  0.123041257 -1.051115447  0.037861251
[246] -0.418434602 -0.157761464  0.608247138  1.935948295  0.439617028
[251] -1.315815590 -1.049744475  0.062626692 -1.437133298 -0.704373190
[256] -1.271545005  1.354488702 -0.189403516  0.121320765 -1.248884701
[261]  0.664119909 -0.458592799  0.575632886  0.113649439  0.313584824
[266] -0.542918937 -0.425286662  0.719118760  1.475071183 -0.097469170
[271] -0.251228074 -1.354732521 -0.002491469 -0.776397056  1.247411198
[276]  0.492605892 -0.267694489  0.871749037 -0.667232411 -0.140691430
[281]  1.486316190 -0.570019533 -0.403186665 -0.934041159 -1.073216781
[286]  0.872836172  1.704860136  2.003395075 -0.444033625 -2.226245202
[291] -0.345753961  0.967543848 -0.801228219  0.022333057  0.713670594
[296]  0.823427572 -0.745086346  0.375469749 -0.153803946 -0.088924780
[301]  0.259511376 -0.438247550 -1.891592052  0.614138665  1.542204879
[306]  0.229570124  2.199194822  1.911824162  0.381447916  0.923876681
[311]  1.569124746  0.190471527 -1.101905591  0.840458813 -1.008612094
[316]  0.963839950 -0.588174466  2.197871622  0.400694457  0.166740003
[321] -0.466734546 -1.052854038 -1.061278642 -0.284756458 -1.294284060
[326] -0.510389063  0.201404878 -0.961955161 -1.247092174  0.868888724
[331] -0.489540788 -0.331229428  0.152316251  0.789382422 -0.564397285
[336]  0.055046019  1.136110879 -0.757379131  0.959280290  0.047797887
[341]  1.806710453  0.207651383  0.569587683  1.841049948 -1.148195373
[346]  0.362523725  1.096106336  0.127342694  0.316965098  1.510262277
[351] -0.515368794 -1.651867077 -0.274307944 -0.206056801 -0.132799054
[356]  0.486266173  0.198682364 -0.851692737 -1.547611328 -0.122007508
[361]  2.186625738  0.014164514  0.407606456  0.087655807 -0.853850289
[366] -0.676147617 -0.122072480  0.498902539 -1.242747849  0.089586503
[371] -0.514530984 -0.634893986 -1.774812727  1.784912793 -0.637310273
[376]  1.084788441 -0.989631955  0.434493324 -1.079552416 -0.114610837
[381] -1.296592068 -1.187866915  0.536017217 -0.075394770 -1.077972230
[386] -0.756981577  0.390582756  0.584742597  0.619748784  1.869386216
[391] -0.291140846  1.221008488 -0.411916659  1.086083140 -1.356417282
[396]  0.175486762 -1.357947323  0.768905836 -0.498909333  0.300724180
[401]  0.396712710  0.585741094 -1.189850881  1.016475479  0.644878243
[406] -0.994231870 -0.061679777 -1.211129558  0.273982970 -0.629107150
[411]  0.927984891 -1.328648007  0.353016309 -1.052833942 -1.071267008
[416]  1.237102443  1.767671357  0.234128097 -0.852850030 -0.479782204
[421]  0.395354668 -0.379406171 -0.834765993 -0.807492623 -0.182761438
[426] -0.392825961  0.813021641  0.128454022  0.464506136  0.232465453
[431]  1.578960891  1.544459873  0.946637343 -0.823675491 -0.087876937
[436] -1.895339800 -1.442775206  0.190212774  2.539674980 -1.065634557
[441]  0.312743919  1.771306739  0.122501166 -1.212779009 -1.922820603
[446] -1.573622650 -0.832564701  0.712097845 -0.357074508  2.344804647
[451] -0.360736805 -0.336356642 -0.513016734 -2.051495458  0.244611311
[456] -0.322820928  0.705821797 -0.840418026  0.413011890  1.566906425
[461] -0.792991398 -0.813543815  0.587609244  0.623640812 -0.327921615
[466] -0.273590178  0.586914426  0.010100460 -2.610325690 -1.058637105
[471]  0.755088178  0.286698683  0.060214560  2.366524395 -0.677956766
[476]  0.567952313 -0.378797682  0.365188354 -0.462094863  0.305380058
[481] -0.348759641 -1.177907417  0.706258975  0.663003657  3.141359262
[486]  1.288169859  0.146009164  0.940103400  0.346212458  1.245818519
[491]  1.141635494 -0.087997994 -1.410313418  0.953382149  0.292003485
[496] -0.234374052  1.622792536 -2.016317175  0.870201914  0.475444218
attr(,"class")
[1] "specialvector" "numeric"      
  [1]  0.209776267 -1.030360010 -2.683244314 -0.598582029 -1.557680867
  [6]  0.313827842 -0.602322142 -0.271172064  1.401769625  0.861991410
 [11] -0.437413971  1.790902173  0.573493437  1.137190595 -0.072726237
 [16]  0.525097544  1.026344245 -0.614522088  2.065700592 -1.533935221
 [21] -0.001201362 -0.924766045 -1.333183264  1.487372772 -1.714447665
 [26]  0.811101690 -0.326313957 -1.033493055  0.498531452 -0.654595614
 [31] -1.323221932 -0.520260785 -0.057443368  0.014895295  0.186655940
 [36]  1.104104927 -0.108047008  0.638683649 -0.485648108 -0.337503611
 [41]  0.667284319 -0.053608559 -1.036029579 -1.216171862 -0.294195055
 [46]  0.367394626  0.461899033  0.225304085  0.294404233  0.731343123
 [51]  1.109236886 -0.714347429  0.185405829 -0.293406452 -0.237118863
 [56] -0.339854109 -1.539213781  0.542319069 -2.093494310 -0.844003284
 [61] -0.548832516  0.487433059 -1.010726613  0.657532456 -1.003483053
 [66] -1.494312404  0.003772973  0.698674329  1.872362809  0.390708593
 [71]  0.253319807 -1.406966288  0.722706849 -0.404125639 -0.165836101
 [76]  2.028698921 -0.832169885  1.124598629  1.654797508  0.309571227
 [81]  0.484517143  1.480256040  0.708233545 -1.028914904  0.825996652
 [86]  0.101659771  1.359229588 -1.130766061  0.604678258 -0.536529559
 [91]  0.209734902  2.028629382 -0.230618920  0.304106177  0.484951142
 [96] -1.130670260  0.948818902  1.196753795 -0.278766042 -1.611013089
[101]  0.041340196 -0.190446887 -0.076806208  0.321798026  0.409749040
[106]  0.624864732 -0.826982981 -0.134393768  0.703411775 -0.787159813
[111] -1.355966440  0.002857996  0.159362845  0.274773550 -1.959072908
[116] -0.007822947 -2.450454520 -0.222355574 -1.076532401 -0.299867765
[121] -0.816509715 -1.729425250 -1.215465332 -0.890949194  0.560203207
[126]  0.758755579 -1.358278160 -0.168206251  0.103618784  1.433714489
[131]  0.065091750  0.006726355  0.235408409 -0.352468394  0.712583489
[136] -1.264236773  1.286904081  0.827597277 -0.341173449 -0.402096755
[141] -0.419011737 -0.621626159 -0.186335760  1.704104927 -0.761226267
[146] -1.610189864  0.189666989 -1.826535381  0.615925609  0.781805245
[151] -1.544666009 -0.627798535 -1.149868342  1.298677843  1.318264410
[156] -1.385332983 -1.044893595  1.225805658 -0.898068094  1.217606589
[161]  1.767950539  0.048782953 -0.392547450 -1.612495105  1.540648605
[166] -0.802886758  1.379476268 -0.814655587  1.341139174 -0.181589255
[171] -0.214068157  1.756063241 -1.028762110 -1.880676486  0.274561855
[176]  0.454012700 -0.406668993 -0.630236006  1.496869494  0.067495367
[181]  2.767094441  0.990917427  0.832225889 -1.494982600  1.413677254
[186] -1.103304232 -0.465162937  0.183868035 -1.868030103 -0.117628001
[191]  0.622618798 -0.538036205 -0.209250379  1.586558380  0.243156875
[196] -0.157343114 -0.828315058  1.137439046 -0.752721143 -0.994831441
[201] -0.136005325 -0.816332177  0.783621130 -1.283490785 -1.368775376
[206]  1.894014939 -1.021640019  0.530346469 -0.924058879 -1.096467456
[211] -0.035692815 -0.526073443 -1.639758062  0.683840443 -1.017800245
[216] -0.347145587 -0.268729468  0.615028393  0.234242186  0.355570461
[221] -0.931370175 -0.456048706  0.159603005  0.297584151 -0.819127169
[226]  1.814704987 -0.919621772  0.930764506 -1.278293991 -0.201841918
[231] -0.766239862  1.564683127 -0.535781294 -0.079413161 -0.550550756
[236] -0.726147169  0.461158588  0.882758834 -1.524965209 -0.192229621
[241] -0.804709667  0.404939063  0.123041257 -1.051115447  0.037861251
[246] -0.418434602 -0.157761464  0.608247138  1.935948295  0.439617028
[251] -1.315815590 -1.049744475  0.062626692 -1.437133298 -0.704373190
[256] -1.271545005  1.354488702 -0.189403516  0.121320765 -1.248884701
[261]  0.664119909 -0.458592799  0.575632886  0.113649439  0.313584824
[266] -0.542918937 -0.425286662  0.719118760  1.475071183 -0.097469170
[271] -0.251228074 -1.354732521 -0.002491469 -0.776397056  1.247411198
[276]  0.492605892 -0.267694489  0.871749037 -0.667232411 -0.140691430
[281]  1.486316190 -0.570019533 -0.403186665 -0.934041159 -1.073216781
[286]  0.872836172  1.704860136  2.003395075 -0.444033625 -2.226245202
[291] -0.345753961  0.967543848 -0.801228219  0.022333057  0.713670594
[296]  0.823427572 -0.745086346  0.375469749 -0.153803946 -0.088924780
[301]  0.259511376 -0.438247550 -1.891592052  0.614138665  1.542204879
[306]  0.229570124  2.199194822  1.911824162  0.381447916  0.923876681
[311]  1.569124746  0.190471527 -1.101905591  0.840458813 -1.008612094
[316]  0.963839950 -0.588174466  2.197871622  0.400694457  0.166740003
[321] -0.466734546 -1.052854038 -1.061278642 -0.284756458 -1.294284060
[326] -0.510389063  0.201404878 -0.961955161 -1.247092174  0.868888724
[331] -0.489540788 -0.331229428  0.152316251  0.789382422 -0.564397285
[336]  0.055046019  1.136110879 -0.757379131  0.959280290  0.047797887
[341]  1.806710453  0.207651383  0.569587683  1.841049948 -1.148195373
[346]  0.362523725  1.096106336  0.127342694  0.316965098  1.510262277
[351] -0.515368794 -1.651867077 -0.274307944 -0.206056801 -0.132799054
[356]  0.486266173  0.198682364 -0.851692737 -1.547611328 -0.122007508
[361]  2.186625738  0.014164514  0.407606456  0.087655807 -0.853850289
[366] -0.676147617 -0.122072480  0.498902539 -1.242747849  0.089586503
[371] -0.514530984 -0.634893986 -1.774812727  1.784912793 -0.637310273
[376]  1.084788441 -0.989631955  0.434493324 -1.079552416 -0.114610837
[381] -1.296592068 -1.187866915  0.536017217 -0.075394770 -1.077972230
[386] -0.756981577  0.390582756  0.584742597  0.619748784  1.869386216
[391] -0.291140846  1.221008488 -0.411916659  1.086083140 -1.356417282
[396]  0.175486762 -1.357947323  0.768905836 -0.498909333  0.300724180
[401]  0.396712710  0.585741094 -1.189850881  1.016475479  0.644878243
[406] -0.994231870 -0.061679777 -1.211129558  0.273982970 -0.629107150
[411]  0.927984891 -1.328648007  0.353016309 -1.052833942 -1.071267008
[416]  1.237102443  1.767671357  0.234128097 -0.852850030 -0.479782204
[421]  0.395354668 -0.379406171 -0.834765993 -0.807492623 -0.182761438
[426] -0.392825961  0.813021641  0.128454022  0.464506136  0.232465453
[431]  1.578960891  1.544459873  0.946637343 -0.823675491 -0.087876937
[436] -1.895339800 -1.442775206  0.190212774  2.539674980 -1.065634557
[441]  0.312743919  1.771306739  0.122501166 -1.212779009 -1.922820603
[446] -1.573622650 -0.832564701  0.712097845 -0.357074508  2.344804647
[451] -0.360736805 -0.336356642 -0.513016734 -2.051495458  0.244611311
[456] -0.322820928  0.705821797 -0.840418026  0.413011890  1.566906425
[461] -0.792991398 -0.813543815  0.587609244  0.623640812 -0.327921615
[466] -0.273590178  0.586914426  0.010100460 -2.610325690 -1.058637105
[471]  0.755088178  0.286698683  0.060214560  2.366524395 -0.677956766
[476]  0.567952313 -0.378797682  0.365188354 -0.462094863  0.305380058
[481] -0.348759641 -1.177907417  0.706258975  0.663003657  3.141359262
[486]  1.288169859  0.146009164  0.940103400  0.346212458  1.245818519
[491]  1.141635494 -0.087997994 -1.410313418  0.953382149  0.292003485
[496] -0.234374052  1.622792536 -2.016317175  0.870201914  0.475444218
attr(,"class")
[1] "specialvector" "numeric"      

To create a custom print() function for out new class specialvector, we define a function named print.[classname]:

print.specialvector <- function(x, ...) {
  cat("This is a special vector of length", length(x), "\n")
  cat("Its mean value is", mean(x, na.rm = TRUE), 
      "and its median is", median(x, na.rm = TRUE))
  cat("\nHere are the first few elements:\n", head(x), "\n")
  invisible(x)
}

Now, when you print an object of class specialvector, the custom print() command is invoked:

x
This is a special vector of length 500 
Its mean value is -0.02106159 and its median is -0.05956157
Here are the first few elements:
 0.2097763 -1.03036 -2.683244 -0.598582 -1.557681 0.3138278 

If needed, you can call the default or another appropriate method directly:

  [1]  0.209776267 -1.030360010 -2.683244314 -0.598582029 -1.557680867
  [6]  0.313827842 -0.602322142 -0.271172064  1.401769625  0.861991410
 [11] -0.437413971  1.790902173  0.573493437  1.137190595 -0.072726237
 [16]  0.525097544  1.026344245 -0.614522088  2.065700592 -1.533935221
 [21] -0.001201362 -0.924766045 -1.333183264  1.487372772 -1.714447665
 [26]  0.811101690 -0.326313957 -1.033493055  0.498531452 -0.654595614
 [31] -1.323221932 -0.520260785 -0.057443368  0.014895295  0.186655940
 [36]  1.104104927 -0.108047008  0.638683649 -0.485648108 -0.337503611
 [41]  0.667284319 -0.053608559 -1.036029579 -1.216171862 -0.294195055
 [46]  0.367394626  0.461899033  0.225304085  0.294404233  0.731343123
 [51]  1.109236886 -0.714347429  0.185405829 -0.293406452 -0.237118863
 [56] -0.339854109 -1.539213781  0.542319069 -2.093494310 -0.844003284
 [61] -0.548832516  0.487433059 -1.010726613  0.657532456 -1.003483053
 [66] -1.494312404  0.003772973  0.698674329  1.872362809  0.390708593
 [71]  0.253319807 -1.406966288  0.722706849 -0.404125639 -0.165836101
 [76]  2.028698921 -0.832169885  1.124598629  1.654797508  0.309571227
 [81]  0.484517143  1.480256040  0.708233545 -1.028914904  0.825996652
 [86]  0.101659771  1.359229588 -1.130766061  0.604678258 -0.536529559
 [91]  0.209734902  2.028629382 -0.230618920  0.304106177  0.484951142
 [96] -1.130670260  0.948818902  1.196753795 -0.278766042 -1.611013089
[101]  0.041340196 -0.190446887 -0.076806208  0.321798026  0.409749040
[106]  0.624864732 -0.826982981 -0.134393768  0.703411775 -0.787159813
[111] -1.355966440  0.002857996  0.159362845  0.274773550 -1.959072908
[116] -0.007822947 -2.450454520 -0.222355574 -1.076532401 -0.299867765
[121] -0.816509715 -1.729425250 -1.215465332 -0.890949194  0.560203207
[126]  0.758755579 -1.358278160 -0.168206251  0.103618784  1.433714489
[131]  0.065091750  0.006726355  0.235408409 -0.352468394  0.712583489
[136] -1.264236773  1.286904081  0.827597277 -0.341173449 -0.402096755
[141] -0.419011737 -0.621626159 -0.186335760  1.704104927 -0.761226267
[146] -1.610189864  0.189666989 -1.826535381  0.615925609  0.781805245
[151] -1.544666009 -0.627798535 -1.149868342  1.298677843  1.318264410
[156] -1.385332983 -1.044893595  1.225805658 -0.898068094  1.217606589
[161]  1.767950539  0.048782953 -0.392547450 -1.612495105  1.540648605
[166] -0.802886758  1.379476268 -0.814655587  1.341139174 -0.181589255
[171] -0.214068157  1.756063241 -1.028762110 -1.880676486  0.274561855
[176]  0.454012700 -0.406668993 -0.630236006  1.496869494  0.067495367
[181]  2.767094441  0.990917427  0.832225889 -1.494982600  1.413677254
[186] -1.103304232 -0.465162937  0.183868035 -1.868030103 -0.117628001
[191]  0.622618798 -0.538036205 -0.209250379  1.586558380  0.243156875
[196] -0.157343114 -0.828315058  1.137439046 -0.752721143 -0.994831441
[201] -0.136005325 -0.816332177  0.783621130 -1.283490785 -1.368775376
[206]  1.894014939 -1.021640019  0.530346469 -0.924058879 -1.096467456
[211] -0.035692815 -0.526073443 -1.639758062  0.683840443 -1.017800245
[216] -0.347145587 -0.268729468  0.615028393  0.234242186  0.355570461
[221] -0.931370175 -0.456048706  0.159603005  0.297584151 -0.819127169
[226]  1.814704987 -0.919621772  0.930764506 -1.278293991 -0.201841918
[231] -0.766239862  1.564683127 -0.535781294 -0.079413161 -0.550550756
[236] -0.726147169  0.461158588  0.882758834 -1.524965209 -0.192229621
[241] -0.804709667  0.404939063  0.123041257 -1.051115447  0.037861251
[246] -0.418434602 -0.157761464  0.608247138  1.935948295  0.439617028
[251] -1.315815590 -1.049744475  0.062626692 -1.437133298 -0.704373190
[256] -1.271545005  1.354488702 -0.189403516  0.121320765 -1.248884701
[261]  0.664119909 -0.458592799  0.575632886  0.113649439  0.313584824
[266] -0.542918937 -0.425286662  0.719118760  1.475071183 -0.097469170
[271] -0.251228074 -1.354732521 -0.002491469 -0.776397056  1.247411198
[276]  0.492605892 -0.267694489  0.871749037 -0.667232411 -0.140691430
[281]  1.486316190 -0.570019533 -0.403186665 -0.934041159 -1.073216781
[286]  0.872836172  1.704860136  2.003395075 -0.444033625 -2.226245202
[291] -0.345753961  0.967543848 -0.801228219  0.022333057  0.713670594
[296]  0.823427572 -0.745086346  0.375469749 -0.153803946 -0.088924780
[301]  0.259511376 -0.438247550 -1.891592052  0.614138665  1.542204879
[306]  0.229570124  2.199194822  1.911824162  0.381447916  0.923876681
[311]  1.569124746  0.190471527 -1.101905591  0.840458813 -1.008612094
[316]  0.963839950 -0.588174466  2.197871622  0.400694457  0.166740003
[321] -0.466734546 -1.052854038 -1.061278642 -0.284756458 -1.294284060
[326] -0.510389063  0.201404878 -0.961955161 -1.247092174  0.868888724
[331] -0.489540788 -0.331229428  0.152316251  0.789382422 -0.564397285
[336]  0.055046019  1.136110879 -0.757379131  0.959280290  0.047797887
[341]  1.806710453  0.207651383  0.569587683  1.841049948 -1.148195373
[346]  0.362523725  1.096106336  0.127342694  0.316965098  1.510262277
[351] -0.515368794 -1.651867077 -0.274307944 -0.206056801 -0.132799054
[356]  0.486266173  0.198682364 -0.851692737 -1.547611328 -0.122007508
[361]  2.186625738  0.014164514  0.407606456  0.087655807 -0.853850289
[366] -0.676147617 -0.122072480  0.498902539 -1.242747849  0.089586503
[371] -0.514530984 -0.634893986 -1.774812727  1.784912793 -0.637310273
[376]  1.084788441 -0.989631955  0.434493324 -1.079552416 -0.114610837
[381] -1.296592068 -1.187866915  0.536017217 -0.075394770 -1.077972230
[386] -0.756981577  0.390582756  0.584742597  0.619748784  1.869386216
[391] -0.291140846  1.221008488 -0.411916659  1.086083140 -1.356417282
[396]  0.175486762 -1.357947323  0.768905836 -0.498909333  0.300724180
[401]  0.396712710  0.585741094 -1.189850881  1.016475479  0.644878243
[406] -0.994231870 -0.061679777 -1.211129558  0.273982970 -0.629107150
[411]  0.927984891 -1.328648007  0.353016309 -1.052833942 -1.071267008
[416]  1.237102443  1.767671357  0.234128097 -0.852850030 -0.479782204
[421]  0.395354668 -0.379406171 -0.834765993 -0.807492623 -0.182761438
[426] -0.392825961  0.813021641  0.128454022  0.464506136  0.232465453
[431]  1.578960891  1.544459873  0.946637343 -0.823675491 -0.087876937
[436] -1.895339800 -1.442775206  0.190212774  2.539674980 -1.065634557
[441]  0.312743919  1.771306739  0.122501166 -1.212779009 -1.922820603
[446] -1.573622650 -0.832564701  0.712097845 -0.357074508  2.344804647
[451] -0.360736805 -0.336356642 -0.513016734 -2.051495458  0.244611311
[456] -0.322820928  0.705821797 -0.840418026  0.413011890  1.566906425
[461] -0.792991398 -0.813543815  0.587609244  0.623640812 -0.327921615
[466] -0.273590178  0.586914426  0.010100460 -2.610325690 -1.058637105
[471]  0.755088178  0.286698683  0.060214560  2.366524395 -0.677956766
[476]  0.567952313 -0.378797682  0.365188354 -0.462094863  0.305380058
[481] -0.348759641 -1.177907417  0.706258975  0.663003657  3.141359262
[486]  1.288169859  0.146009164  0.940103400  0.346212458  1.245818519
[491]  1.141635494 -0.087997994 -1.410313418  0.953382149  0.292003485
[496] -0.234374052  1.622792536 -2.016317175  0.870201914  0.475444218
attr(,"class")
[1] "specialvector" "numeric"      

You can change the vector back to a regular numeric vector, or a different class, just as easily:

class(x) <- "numeric"
x
  [1]  0.209776267 -1.030360010 -2.683244314 -0.598582029 -1.557680867
  [6]  0.313827842 -0.602322142 -0.271172064  1.401769625  0.861991410
 [11] -0.437413971  1.790902173  0.573493437  1.137190595 -0.072726237
 [16]  0.525097544  1.026344245 -0.614522088  2.065700592 -1.533935221
 [21] -0.001201362 -0.924766045 -1.333183264  1.487372772 -1.714447665
 [26]  0.811101690 -0.326313957 -1.033493055  0.498531452 -0.654595614
 [31] -1.323221932 -0.520260785 -0.057443368  0.014895295  0.186655940
 [36]  1.104104927 -0.108047008  0.638683649 -0.485648108 -0.337503611
 [41]  0.667284319 -0.053608559 -1.036029579 -1.216171862 -0.294195055
 [46]  0.367394626  0.461899033  0.225304085  0.294404233  0.731343123
 [51]  1.109236886 -0.714347429  0.185405829 -0.293406452 -0.237118863
 [56] -0.339854109 -1.539213781  0.542319069 -2.093494310 -0.844003284
 [61] -0.548832516  0.487433059 -1.010726613  0.657532456 -1.003483053
 [66] -1.494312404  0.003772973  0.698674329  1.872362809  0.390708593
 [71]  0.253319807 -1.406966288  0.722706849 -0.404125639 -0.165836101
 [76]  2.028698921 -0.832169885  1.124598629  1.654797508  0.309571227
 [81]  0.484517143  1.480256040  0.708233545 -1.028914904  0.825996652
 [86]  0.101659771  1.359229588 -1.130766061  0.604678258 -0.536529559
 [91]  0.209734902  2.028629382 -0.230618920  0.304106177  0.484951142
 [96] -1.130670260  0.948818902  1.196753795 -0.278766042 -1.611013089
[101]  0.041340196 -0.190446887 -0.076806208  0.321798026  0.409749040
[106]  0.624864732 -0.826982981 -0.134393768  0.703411775 -0.787159813
[111] -1.355966440  0.002857996  0.159362845  0.274773550 -1.959072908
[116] -0.007822947 -2.450454520 -0.222355574 -1.076532401 -0.299867765
[121] -0.816509715 -1.729425250 -1.215465332 -0.890949194  0.560203207
[126]  0.758755579 -1.358278160 -0.168206251  0.103618784  1.433714489
[131]  0.065091750  0.006726355  0.235408409 -0.352468394  0.712583489
[136] -1.264236773  1.286904081  0.827597277 -0.341173449 -0.402096755
[141] -0.419011737 -0.621626159 -0.186335760  1.704104927 -0.761226267
[146] -1.610189864  0.189666989 -1.826535381  0.615925609  0.781805245
[151] -1.544666009 -0.627798535 -1.149868342  1.298677843  1.318264410
[156] -1.385332983 -1.044893595  1.225805658 -0.898068094  1.217606589
[161]  1.767950539  0.048782953 -0.392547450 -1.612495105  1.540648605
[166] -0.802886758  1.379476268 -0.814655587  1.341139174 -0.181589255
[171] -0.214068157  1.756063241 -1.028762110 -1.880676486  0.274561855
[176]  0.454012700 -0.406668993 -0.630236006  1.496869494  0.067495367
[181]  2.767094441  0.990917427  0.832225889 -1.494982600  1.413677254
[186] -1.103304232 -0.465162937  0.183868035 -1.868030103 -0.117628001
[191]  0.622618798 -0.538036205 -0.209250379  1.586558380  0.243156875
[196] -0.157343114 -0.828315058  1.137439046 -0.752721143 -0.994831441
[201] -0.136005325 -0.816332177  0.783621130 -1.283490785 -1.368775376
[206]  1.894014939 -1.021640019  0.530346469 -0.924058879 -1.096467456
[211] -0.035692815 -0.526073443 -1.639758062  0.683840443 -1.017800245
[216] -0.347145587 -0.268729468  0.615028393  0.234242186  0.355570461
[221] -0.931370175 -0.456048706  0.159603005  0.297584151 -0.819127169
[226]  1.814704987 -0.919621772  0.930764506 -1.278293991 -0.201841918
[231] -0.766239862  1.564683127 -0.535781294 -0.079413161 -0.550550756
[236] -0.726147169  0.461158588  0.882758834 -1.524965209 -0.192229621
[241] -0.804709667  0.404939063  0.123041257 -1.051115447  0.037861251
[246] -0.418434602 -0.157761464  0.608247138  1.935948295  0.439617028
[251] -1.315815590 -1.049744475  0.062626692 -1.437133298 -0.704373190
[256] -1.271545005  1.354488702 -0.189403516  0.121320765 -1.248884701
[261]  0.664119909 -0.458592799  0.575632886  0.113649439  0.313584824
[266] -0.542918937 -0.425286662  0.719118760  1.475071183 -0.097469170
[271] -0.251228074 -1.354732521 -0.002491469 -0.776397056  1.247411198
[276]  0.492605892 -0.267694489  0.871749037 -0.667232411 -0.140691430
[281]  1.486316190 -0.570019533 -0.403186665 -0.934041159 -1.073216781
[286]  0.872836172  1.704860136  2.003395075 -0.444033625 -2.226245202
[291] -0.345753961  0.967543848 -0.801228219  0.022333057  0.713670594
[296]  0.823427572 -0.745086346  0.375469749 -0.153803946 -0.088924780
[301]  0.259511376 -0.438247550 -1.891592052  0.614138665  1.542204879
[306]  0.229570124  2.199194822  1.911824162  0.381447916  0.923876681
[311]  1.569124746  0.190471527 -1.101905591  0.840458813 -1.008612094
[316]  0.963839950 -0.588174466  2.197871622  0.400694457  0.166740003
[321] -0.466734546 -1.052854038 -1.061278642 -0.284756458 -1.294284060
[326] -0.510389063  0.201404878 -0.961955161 -1.247092174  0.868888724
[331] -0.489540788 -0.331229428  0.152316251  0.789382422 -0.564397285
[336]  0.055046019  1.136110879 -0.757379131  0.959280290  0.047797887
[341]  1.806710453  0.207651383  0.569587683  1.841049948 -1.148195373
[346]  0.362523725  1.096106336  0.127342694  0.316965098  1.510262277
[351] -0.515368794 -1.651867077 -0.274307944 -0.206056801 -0.132799054
[356]  0.486266173  0.198682364 -0.851692737 -1.547611328 -0.122007508
[361]  2.186625738  0.014164514  0.407606456  0.087655807 -0.853850289
[366] -0.676147617 -0.122072480  0.498902539 -1.242747849  0.089586503
[371] -0.514530984 -0.634893986 -1.774812727  1.784912793 -0.637310273
[376]  1.084788441 -0.989631955  0.434493324 -1.079552416 -0.114610837
[381] -1.296592068 -1.187866915  0.536017217 -0.075394770 -1.077972230
[386] -0.756981577  0.390582756  0.584742597  0.619748784  1.869386216
[391] -0.291140846  1.221008488 -0.411916659  1.086083140 -1.356417282
[396]  0.175486762 -1.357947323  0.768905836 -0.498909333  0.300724180
[401]  0.396712710  0.585741094 -1.189850881  1.016475479  0.644878243
[406] -0.994231870 -0.061679777 -1.211129558  0.273982970 -0.629107150
[411]  0.927984891 -1.328648007  0.353016309 -1.052833942 -1.071267008
[416]  1.237102443  1.767671357  0.234128097 -0.852850030 -0.479782204
[421]  0.395354668 -0.379406171 -0.834765993 -0.807492623 -0.182761438
[426] -0.392825961  0.813021641  0.128454022  0.464506136  0.232465453
[431]  1.578960891  1.544459873  0.946637343 -0.823675491 -0.087876937
[436] -1.895339800 -1.442775206  0.190212774  2.539674980 -1.065634557
[441]  0.312743919  1.771306739  0.122501166 -1.212779009 -1.922820603
[446] -1.573622650 -0.832564701  0.712097845 -0.357074508  2.344804647
[451] -0.360736805 -0.336356642 -0.513016734 -2.051495458  0.244611311
[456] -0.322820928  0.705821797 -0.840418026  0.413011890  1.566906425
[461] -0.792991398 -0.813543815  0.587609244  0.623640812 -0.327921615
[466] -0.273590178  0.586914426  0.010100460 -2.610325690 -1.058637105
[471]  0.755088178  0.286698683  0.060214560  2.366524395 -0.677956766
[476]  0.567952313 -0.378797682  0.365188354 -0.462094863  0.305380058
[481] -0.348759641 -1.177907417  0.706258975  0.663003657  3.141359262
[486]  1.288169859  0.146009164  0.940103400  0.346212458  1.245818519
[491]  1.141635494 -0.087997994 -1.410313418  0.953382149  0.292003485
[496] -0.234374052  1.622792536 -2.016317175  0.870201914  0.475444218
© 2025 E.D. Gennatas