Load a bigSNP from backing files into R.

snp_attach(rdsfile)

Arguments

rdsfile

The path of the ".rds" which stores the bigSNP object.

Value

The bigSNP object.

Details

This is often just a call to readRDS. But it also checks if you have moved the two (".bk" and ".rds") backing files to another directory.

Examples

(bedfile <- system.file("extdata", "example.bed", package = "bigsnpr"))
#> [1] "C:/Users/au639593/AppData/Local/Temp/RtmpCcuoXf/temp_libpath50e85e914cf4/bigsnpr/extdata/example.bed"

# Reading the bedfile and storing the data in temporary directory
rds <- snp_readBed(bedfile, backingfile = tempfile())

# Loading the data from backing files
test <- snp_attach(rds)

str(test)
#> List of 3
#>  $ genotypes:Reference class 'FBM.code256' [package "bigstatsr"] with 16 fields
#>   ..$ extptr      :<externalptr> 
#>   ..$ extptr_rw   :<externalptr> 
#>   ..$ nrow        : int 517
#>   ..$ ncol        : int 4542
#>   ..$ type        : Named int 1
#>   .. ..- attr(*, "names")= chr "unsigned char"
#>   ..$ backingfile : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpITJXCm\\file5f8c1312c29.bk"
#>   ..$ is_read_only: logi FALSE
#>   ..$ address     :<externalptr> 
#>   ..$ address_rw  :<externalptr> 
#>   ..$ bk          : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpITJXCm\\file5f8c1312c29.bk"
#>   ..$ rds         : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpITJXCm\\file5f8c1312c29.rds"
#>   ..$ is_saved    : logi TRUE
#>   ..$ type_chr    : chr "unsigned char"
#>   ..$ type_size   : int 1
#>   ..$ file_size   : num 2348214
#>   ..$ code256     : num [1:256] 0 1 2 NA NA NA NA NA NA NA ...
#>   ..and 26 methods, of which 12 are  possibly relevant:
#>   ..  add_columns, as.FBM, bm, bm.desc, check_dimensions,
#>   ..  check_write_permissions, copy#envRefClass, initialize, initialize#FBM,
#>   ..  save, show#FBM, show#envRefClass
#>  $ fam      :'data.frame':	517 obs. of  6 variables:
#>   ..$ family.ID  : chr [1:517] "POP1" "POP1" "POP1" "POP1" ...
#>   ..$ sample.ID  : chr [1:517] "IND0" "IND1" "IND2" "IND3" ...
#>   ..$ paternal.ID: int [1:517] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ maternal.ID: int [1:517] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ sex        : int [1:517] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ affection  : int [1:517] 1 1 2 1 1 1 1 1 1 1 ...
#>  $ map      :'data.frame':	4542 obs. of  6 variables:
#>   ..$ chromosome  : int [1:4542] 1 1 1 1 1 1 1 1 1 1 ...
#>   ..$ marker.ID   : chr [1:4542] "SNP0" "SNP1" "SNP2" "SNP3" ...
#>   ..$ genetic.dist: int [1:4542] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ physical.pos: int [1:4542] 112 1098 2089 3107 4091 5091 6107 7103 8090 9074 ...
#>   ..$ allele1     : chr [1:4542] "A" "T" "T" "T" ...
#>   ..$ allele2     : chr [1:4542] "T" "A" "A" "A" ...
#>  - attr(*, "class")= chr "bigSNP"
dim(G <- test$genotypes)
#> [1]  517 4542
G[1:8, 1:8]
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,]    0    0    2    0    1    1    0    2
#> [2,]    1    0    1    0    0    1    0    2
#> [3,]    0    1    1    0    2    1    0    2
#> [4,]    0    0    2    0    2    1    0    2
#> [5,]    1    0    0    0    2    2    1    0
#> [6,]    0    1    0    0    2    1    0    0
#> [7,]    0    1    1    0    2    2    1    1
#> [8,]    1    0    1    1    1    1    0    1