Deep copy of a Filebacked Big Matrix with possible subsetting. This should also work for any matrix-like object.

big_copy(
  X,
  ind.row = rows_along(X),
  ind.col = cols_along(X),
  type = typeof(X),
  backingfile = tempfile(),
  block.size = block_size(length(ind.row)),
  is_read_only = FALSE
)

Arguments

X

Could be any matrix-like object.

ind.row

An optional vector of the row indices that are used. If not specified, all rows are used. Don't use negative indices.

ind.col

An optional vector of the column indices that are used. If not specified, all columns are used. Don't use negative indices.

type

Type of the Filebacked Big Matrix (default is double). Either

  • "double" (double precision -- 64 bits)

  • "float" (single precision -- 32 bits)

  • "integer"

  • "unsigned short": can store integer values from 0 to 65535. It has vocation to become the basis for a FBM.code65536.

  • "raw" or "unsigned char": can store integer values from 0 to 255. It is the basis for class FBM.code256 in order to access 256 arbitrary different numeric values. It is used in package bigsnpr.

backingfile

Path to the file storing the Big Matrix on disk. An extension ".bk" will be automatically added. Default stores in the temporary directory.

block.size

Maximum number of columns read at once. Default uses block_size.

is_read_only

Whether the FBM is read-only? Default is FALSE.

Value

A copy of X as a new FBM object.

Examples

X <- FBM(10, 10, init = 1:100) X[]
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 1 11 21 31 41 51 61 71 81 91 #> [2,] 2 12 22 32 42 52 62 72 82 92 #> [3,] 3 13 23 33 43 53 63 73 83 93 #> [4,] 4 14 24 34 44 54 64 74 84 94 #> [5,] 5 15 25 35 45 55 65 75 85 95 #> [6,] 6 16 26 36 46 56 66 76 86 96 #> [7,] 7 17 27 37 47 57 67 77 87 97 #> [8,] 8 18 28 38 48 58 68 78 88 98 #> [9,] 9 19 29 39 49 59 69 79 89 99 #> [10,] 10 20 30 40 50 60 70 80 90 100
X2 <- big_copy(X, ind.row = 1:5) X2[]
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 1 11 21 31 41 51 61 71 81 91 #> [2,] 2 12 22 32 42 52 62 72 82 92 #> [3,] 3 13 23 33 43 53 63 73 83 93 #> [4,] 4 14 24 34 44 54 64 74 84 94 #> [5,] 5 15 25 35 45 55 65 75 85 95
mat <- matrix(101:200, 10) X3 <- big_copy(mat, type = "double") # as_FBM() would be faster here X3[]
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 101 111 121 131 141 151 161 171 181 191 #> [2,] 102 112 122 132 142 152 162 172 182 192 #> [3,] 103 113 123 133 143 153 163 173 183 193 #> [4,] 104 114 124 134 144 154 164 174 184 194 #> [5,] 105 115 125 135 145 155 165 175 185 195 #> [6,] 106 116 126 136 146 156 166 176 186 196 #> [7,] 107 117 127 137 147 157 167 177 187 197 #> [8,] 108 118 128 138 148 158 168 178 188 198 #> [9,] 109 119 129 139 149 159 169 179 189 199 #> [10,] 110 120 130 140 150 160 170 180 190 200
X.code <- big_attachExtdata() class(X.code)
#> [1] "FBM.code256" #> attr(,"package") #> [1] "bigstatsr"
X2.code <- big_copy(X.code) class(X2.code)
#> [1] "FBM.code256" #> attr(,"package") #> [1] "bigstatsr"
all.equal(X.code[], X2.code[])
#> [1] TRUE