2016-06-16 80 views
2

如果使用dput()爲柵格對象的結構使用raster包,然後分配該結構返回到一個新的對象時會引發錯誤如何dput()的光柵

Error in datanotation %in% c("LOG1S", "INT1S", "INT2S", "INT4S", "INT1U", : 
    error in evaluating the argument 'x' in selecting a method for function '%in%': Error: object 'datanotation' not found 

實施例創建的輸出從dput輸出來測試此上:

rast <- new("RasterLayer", file = new(".RasterFile" 
         , name = "" 
         , datanotation = "FLT4S" 
         , byteorder = "little" 
         , nodatavalue = -Inf 
         , NAchanged = FALSE 
         , nbands = 1L 
         , bandorder = "BIL" 
         , offset = 0L 
         , toptobottom = TRUE 
         , blockrows = 0L 
         , blockcols = 0L 
         , driver = "" 
         , open = FALSE 
      ) 
      , data = new(".SingleLayerData" 
         , values = c(NA, NA, NA, NA, 27.7696047300953, 25.8297302967319, 21.8282877533719, 
             18.2355885882618, 27.0557882676846, 27.2210269605054, NA, NA, 
             NA, NA, NA, NA, NA, NA, NA, NA, NA, 27.7812364734848, 27.405183119753, 
             24.2674419226904, 21.1096354803572, 19.7839120235376, 28.0337762198564, 
             30.3552042477317, 27.9129238649901, NA, NA, NA, NA, NA, NA, NA, 
             NA, NA, NA, 27.8602581108286, 25.5695030720577, 19.308317452836, 
             20.2224030952562, 19.8943689815922, 26.0737945219631, 29.8730429910469, 
             30.0356550838097, NA, NA, NA, NA, NA, NA, NA, NA, NA, 27.9364248138976, 
             26.9457930700303, 23.0304323166943, 19.4650798632613, 19.0999036995668, 
             17.5193560841074, 27.7251998095169, 28.4496104452209, 28.9315408261731, 
             NA, NA, NA, NA, NA, NA, NA, NA, NA, 26.8544908125766, 25.0566493895284, 
             19.392461671792, 17.9138961574326, 18.457466509715, 16.2828861956587, 
             24.3601694045773, 28.1808209395655, 28.9282707782622, 26.6332021683416, 
             NA, NA, NA, NA, NA, NA, NA, 25.7558302469057, 25.8550702427802, 
             22.56930, 19.6993922601795, 16.1425172340908, 18.5221217322922, 
             15.6749250516081, 23.7808882591915, 26.8347423074187, 27.2630654814702, 
             25.9184967686647, NA, NA, NA, NA, NA, NA, NA, 24.8123372469289, 
             21.9120014347897, 21.8593245154305, 18.7720082061109, 19.7574885247249, 
             18.4980326509342, 16.3585539605331, 24.9138993320561, 25.2434828477134, 
             24.163634092843, 21.0163621891882, 20.415437668758, NA, NA, NA, 
             NA, NA, NA, 24.1877819407117, 20.6452893546199, 20.1902008603325, 
             19.3002926063194, 16.8587312480956, 16.2594198755341, 19.2032612963314, 
             23.627249155838, 20.2610810034085, 20.512646252079, 21.2108132984962, 
             21.3929956864179, 22.5462104762584, NA, NA, NA, NA, 28.1377507911064, 
             26.6783600800768, 21.9226216069185, 18.7325546681671, 19.3040954243679, 
             18.9295032049331, 16.9754437056141, 18.4150075374079, 22.1472527043877, 
             23.0212426364059, 24.3613220176048, 23.8262550760194, 23.1817611577951, 
             23.5871416966677, 24.5249361302642, 24.8507563698565, 24.5380700828535, 
             24.6222669309606, 28.1310406991608, 26.6318516890262, 22.2093701933002, 
             18.5946021290531, 18.8365649393596, 19.1392679329481, 18.0261774155026, 
             15.4867865984622, 22.6594382919435, 24.0000969920539, 26.8590549383737, 
             25.3828920205212, 24.7396876533108, 24.2529425383968, 25.4417776029091, 
             25.4515553773556, 25.362837214521, 24.9104771169439, NA, 26.0466484214637, 
             22.5547365784066, 21.385068811716, 21.7011412999039, 21.5908931968994, 
             17.5042944634609, 16.1420136345859, 22.2389789351034, 24.9668657681713, 
             27.1669375893459, 26.7413589409561, 26.421134458086, 26.219636989708, 
             26.3182362528439, 26.4198369697735, 26.3436222765849, NA, NA, 
             NA, 23.0141531354431, 25.0932401677589, 21.6662460243741, 20.5190520941524, 
             18.375683158989, 21.0476911567136, 24.5643254483451, 26.328155553503, 
             26.272891752264, 27.9174179692592, 27.8104921435185, 27.3675508861065, 
             27.0387799062499, 26.7967626268208, NA, NA, NA, NA, 23.9459211033352, 
             27.0411266756461, 24.5366020483741, 21.827679045105, 20.9547907819176, 
             22.0691273897516, 23.4745553057174, 26.3462307150211, 28.3701287602482, 
             27.3758861302374, 27.3750656061461, 27.962003557149, 27.5345722331493, 
             NA, NA, NA, NA, NA, NA, 28.2432491874035, 25.6912040459346, 23.8651528078732, 
             21.6046243626329, 22.9131480337219, 23.819129269607, 26.3568262380137, 
             28.9188481472128, 28.1497370861287, 27.7360100735352, NA, NA, 
             NA, NA, NA, NA, NA, NA, NA, NA, 25.045874725646, 23.2493769507419, 
             23.1730515314323, 24.2038209656421, 28.3416254663092, 28.8959112067936, 
             NA, NA, NA, NA, NA, NA, NA) 
         , offset = 0 
         , gain = 1 
         , inmemory = TRUE 
         , fromdisk = FALSE 
         , isfactor = FALSE 
         , attributes = list() 
         , haveminmax = TRUE 
         , min = 15.4867865984622 
         , max = 30.3552042477317 
         , band = 1L 
         , unit = "" 
         , names = "MAT_eclp" 
      ) 
      , legend = new(".RasterLegend" 
          , type = character(0) 
          , values = logical(0) 
          , color = logical(0) 
          , names = logical(0) 
          , colortable = logical(0) 
      ) 
      , title = character(0) 
      , extent = new("Extent" 
          , xmin = 832565.530013465 
          , xmax = 2452565.53001346 
          , ymin = 383803.949813352 
          , ymax = 1733803.94981335 
      ) 
      , rotated = FALSE 
      , rotation = new(".Rotation" 
          , geotrans = numeric(0) 
          , transfun = function() 
           NULL 
      ) 
      , ncols = 18L 
      , nrows = 15L 
      , crs = new("CRS" 
         , projargs = "+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0" 
      ) 
      , history = list() 
      , z = list() 
) 

或者,另一個最小例子dput(),然後嘗試另一個對象分配輸出:

library(raster) 
r1 <- raster(nrow=10, ncol=10) 
values(r1) <- runif(ncell(r1)) 
dput(r1) 

如何從文本版本加載柵格並避免此錯誤?

回答

2

這是一個錯誤,因爲.RasterFile對象(RasterLayer的一部分)的有效性檢查出錯。這裏所示:

x <- new(".RasterFile") 
validObject(x) 
#Error in datanotation %in% c("LOG1S", "INT1S", "INT2S", "INT4S", "INT1U", : 
# object 'datanotation' not found 

我(在一個小時內可以從R-僞造或者這樣:install.packages("raster", repos="http://R-Forge.R-project.org"))固定在這個版本2.5-11。

P.S.你爲什麼要使用dput/dget?

+0

問題的原因是我認爲我有一個與柵格內容相關的問題,我想要一個簡單的方法來發布柵格結構以及關於SO的問題。管理解決我的問題無論如何,所以實際上不再需要這個。我想這是一個不尋常的事情,因爲如果需要將數據作爲支持問題的數據,大多數人只需發佈光柵文件的下載鏈接,但我認爲問題應儘可能自我包含,而不要依賴於外部鏈接如果可能。 – dww

+1

不夠公平,但通常要做的是在內存中創建一個RasterLayer,像'r < - raster(xmn = 832565,xmx = 2452565,ymn = 383803,ymx = 1733803,ncol = 18,nrow = 15,crs = 「+ proj = aea + lat_1 = 20 + lat_2 = -23 + lat_0 = 0 + lon_0 = 25 + x_0 = 0 + y_0 = 0 + datum = WGS84」)'然後像數值(r) - runif(ncell(r))'。如果有什麼可以看出你的問題是通用的還是隻發生在特定的數據集中(在這種情況下,你可以使用values(r)<-c(NA,NA,NA,NA,27.8,25.8,21.8,18.2 ,... [這裏沒有足夠的空間]) – RobertH