################################################### ### chunk number 1: setup ################################################### #line 18 "NetCDF-lab.Rnw" options(width = 40) ################################################### ### chunk number 2: scanIntro ################################################### #line 61 "NetCDF-lab.Rnw" library(AdvancedR2011Data) pth <- system.file("extdata", "snpData.csv", package = "AdvancedR2011Data") dat <- scan(pth, what = character(0), sep =",", skip = 600, nlines = 1, quiet = TRUE) ################################################### ### chunk number 3: rowAccess ################################################### #line 95 "NetCDF-lab.Rnw" library(ncdf) st <- system.time ncFile <- system.file("extdata", "snpData.nc", package = "AdvancedR2011Data") nc <- open.ncdf(ncFile, write = FALSE) st(dat <- get.var.ncdf(nc, varid = "snpData", start= c(601,1), count = c(1, 113735))) csvFile <- system.file("extdata", "snpData.csv", package = "AdvancedR2011Data") st(origDat <- scan(csvFile, what = integer(0), sep =",", skip = 600, nlines = 1, quiet = TRUE)) identical(as.vector(dat), origDat) invisible(close.ncdf(nc)) ################################################### ### chunk number 4: colAccess eval=FALSE ################################################### ## #line 160 "NetCDF-lab.Rnw" ## library(StudentGWAS) ## getNcdfVarSummary <- StudentGWAS:::getNcdfVarSummary ## getGWAScols <- function(nc, first, last = first) ## { ## if (!is.numeric(first) || length(first) != 1 || is.na(first)) ## stop("'first' must be a single integer") ## if (!is.numeric(last) || length(last) != 1 || is.na(last)) ## stop("'last' must be a single integer") ## ncInfo <- getNcdfVarSummary(nc, "snpData") ## nrows <- ncInfo$dim1 ## ncols <- ncInfo$dim2 ## if (first < 1 || last < first || last > ncols) ## stop("we need to have 1 <= 'first' <= 'last' <= nb col in NetCDF file") ## dat <- get.var.ncdf(nc, varid = "snpData", start= c(1,first), ## count = c(nrows, last - first + 1)) ## structure(as.raw(dat), dim = dim(dat)) ## } ## ## pth <- system.file("extdata", "small_snpData.nc", package = "StudentGWAS") ## nc <- open.ncdf(pth) ## dat <- getGWAScols(nc, 1, 4) ## invisible(close.ncdf(nc)) ################################################### ### chunk number 5: unitTest eval=FALSE ################################################### ## #line 216 "NetCDF-lab.Rnw" ## library(ncdf) ## testGWAScols <- function() ## { ## pth <- system.file("extdata", "small_snpData.nc", package = "StudentGWAS") ## nc <- open.ncdf(pth, write = FALSE) ## ncols <- getNcdfVarSummary(nc, "snpData")$dim2 ## current <- getGWAScols(nc, 1, ncols) ## load(system.file("extdata", "small_snpData.rda", package = "StudentGWAS")) ## identical(current, small_snpData) ## } ## testGWAScols()