Save a bigSNP after having made some modifications to it. As bigSNP is an S3 class, you can add any slot you want to an object of this class, then use snp_save to save these modifications in the corresponding ".rds" backing file.

snp_save(x, version = NULL)

Arguments

x

A bigSNP.

version

the workspace format version to use. NULL specifies the current default version (3). The only other supported value is 2, the default from R 1.4.0 to R 3.5.0.

Value

The (saved) bigSNP.

Examples

set.seed(1)

# Reading example
test <- snp_attachExtdata()

# I can add whatever I want to an S3 class
test$map$`p-values` <- runif(nrow(test$map))
str(test$map)
#> 'data.frame':	4542 obs. of  7 variables:
#>  $ chromosome  : int  1 1 1 1 1 1 1 1 1 1 ...
#>  $ marker.ID   : chr  "SNP0" "SNP1" "SNP2" "SNP3" ...
#>  $ genetic.dist: int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ physical.pos: int  112 1098 2089 3107 4091 5091 6107 7103 8090 9074 ...
#>  $ allele1     : chr  "A" "T" "T" "T" ...
#>  $ allele2     : chr  "T" "A" "A" "A" ...
#>  $ p-values    : num  0.266 0.372 0.573 0.908 0.202 ...

# Reading again
rds <- test$genotypes$rds
test2 <- snp_attach(rds)
str(test2$map) # new slot wasn't saved
#> 'data.frame':	4542 obs. of  6 variables:
#>  $ chromosome  : int  1 1 1 1 1 1 1 1 1 1 ...
#>  $ marker.ID   : chr  "SNP0" "SNP1" "SNP2" "SNP3" ...
#>  $ genetic.dist: int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ physical.pos: int  112 1098 2089 3107 4091 5091 6107 7103 8090 9074 ...
#>  $ allele1     : chr  "A" "T" "T" "T" ...
#>  $ allele2     : chr  "T" "A" "A" "A" ...

# Save it
snp_save(test)

# Reading again
test3 <- snp_attach(rds)
str(test3$map) # it is saved now
#> 'data.frame':	4542 obs. of  7 variables:
#>  $ chromosome  : int  1 1 1 1 1 1 1 1 1 1 ...
#>  $ marker.ID   : chr  "SNP0" "SNP1" "SNP2" "SNP3" ...
#>  $ genetic.dist: int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ physical.pos: int  112 1098 2089 3107 4091 5091 6107 7103 8090 9074 ...
#>  $ allele1     : chr  "A" "T" "T" "T" ...
#>  $ allele2     : chr  "T" "A" "A" "A" ...
#>  $ p-values    : num  0.266 0.372 0.573 0.908 0.202 ...

# The complicated code of this function
snp_save
#> function (x, version = NULL) 
#> {
#>     saveRDS(x, file = x$genotypes$rds, version = version)
#>     invisible(x)
#> }
#> <bytecode: 0x0000018d82afdb80>
#> <environment: namespace:bigsnpr>