[R-sig-Geo] Cryptic warning when reading raster which consists only of NULL
Rainer M Krug
Rainer at krugs.de
Tue Sep 17 12:10:17 CEST 2013
Hi
When reading a raster from GRASS which consists only of NULL, a cryptic
warning is received:
,----
| Warning in lapply(lres, as.numeric) : NAs introduced by coercion
`----
This is caused by the line
,----
| lres <- lapply(lres, as.numeric)
`----
in the debug session below:
,----
| debug: con <- textConnection(tx)
| Browse[2]>
| debug: res <- read.dcf(con)
| Browse[2]>
| debug: close(con)
| Browse[2]>
| debug: lres <- as.list(res)
| Browse[2]>
| debug: names(lres) <- colnames(res)
| Browse[2]>
| debug: lres <- lapply(lres, as.numeric)
| Browse[2]>
| Warning in lapply(lres, as.numeric) : NAs introduced by coercion
| Warning in lapply(lres, as.numeric) : NAs introduced by coercion
| debug: if (!is.numeric(lres$min) || !is.finite(as.double(lres$min))) NODATA <- as.integer(999) else {
| lres$min <- floor(as.double(lres$min))
| NODATA <- floor(lres$min) - 1
| }
| Browse[2]> lres
| $min
| [1] NA
|
| $max
| [1] NA
|
| Browse[2]> tx
| [1] "min:NULL" "max:NULL"
| Browse[2]>
`----
I would suggest to add thwe statements
,----
| if (lres[[1]]=="NULL") lrews[[1]] <- NA
| if (lres[[2]]=="NULL") lrews[[2]] <- NA
`----
before the line
,----
| lres <- lapply(lres, as.numeric)
`----
as this would replace the "NULL" with NA and not cause the error.
,----
| > sessionInfo()
| R version 3.0.1 (2013-05-16)
| Platform: x86_64-apple-darwin10.8.0 (64-bit)
|
| locale:
| [1] C
|
| attached base packages:
| [1] stats graphics grDevices utils datasets methods base
|
| other attached packages:
| [1] asmDrak_0.0-1 maptools_0.8-27 simecol_0.8-2
| [4] lattice_0.20-23 deSolve_1.10-7 prioritization_0.0-1
| [7] seedGerm_0.0-1 seedDisp_0.4-13 Rcpp_0.10.4
| [10] seedProd_0.0-1 fireSim_0.0-1 RSQLite_0.11.4
| [13] DBI_0.2-7 spgrass6_0.8-3 XML_3.95-0.2
| [16] sp_1.0-13 logger_0.0-1 devtools_1.3.99
|
| loaded via a namespace (and not attached):
| [1] RCurl_1.95-4.1 compiler_3.0.1 digest_0.6.3 evaluate_0.4.7 foreign_0.8-53
| [6] grid_3.0.1 httr_0.2 memoise_0.1 parallel_3.0.1 stringr_0.6.2
| [11] tools_3.0.1 whisker_0.3-2
|
| > version
| _
| platform x86_64-apple-darwin10.8.0
| arch x86_64
| os darwin10.8.0
| system x86_64, darwin10.8.0
| status
| major 3
| minor 0.1
| year 2013
| month 05
| day 16
| svn rev 62743
| language R
| version.string R version 3.0.1 (2013-05-16)
| nickname Good Sport
`----
Thanks,
Rainer
--
Rainer M. Krug
email: RMKrug<at>gmail<dot>com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 486 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130917/19ed9641/attachment.bin>
More information about the R-sig-Geo
mailing list