title: autokriging and SpatialPixel grid file
body: <p>I am trying to use autoKrige in automap package.
  My data looks like</p>
  <pre><code>head(LL12)
  
    Location Longitude  Latitude   percent
  1       L1  16.48476 -28.60737 1.0000000
  2       L3  16.90045 -29.24154 1.0000000
  3       L4  16.99268 -28.44906 0.6363636
  4       L5  17.06871 -29.67825 1.0000000
  5       L6  17.09935 -29.00169 0.6000000
  6       L7  17.25630 -28.82418 1.0000000
  </code></pre>
  <p>and I am trying to plot this in a South African map.</p>
  <p>First I obtained the grid following <a href="https://stackoverflow.com/questions/43436466/create-grid-in-r-for-kriging-in-gstat">Create Grid in R for kriging in gstat</a></p>
  <pre><code>SAgrd &lt;- makegrid(SApol_border, n = 1000)
  
  colnames(SAgrd) &lt;- c('lon','lat')
  
  SAgrd_pts &lt;- SpatialPoints(coords = SAgrd, 
                             proj4string=CRS(proj4string(SApol_border)))
  
  
  SAgrd_pts_in &lt;- SAgrd_pts[SApol_border, ]
  
  plot(SAgrd_pts_in)
  
  plot(SAgrd_pts_in)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/B4qyP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B4qyP.png" alt="enter image description here" /></a></p>
  <p>then I convert it to a SpatialPixel dataframe</p>
  <pre><code>SAgrd_pts_in = as(SAgrd_pts_in,&quot;SpatialPixelsDataFrame&quot;) 
  </code></pre>
  <p>but <code>plot(SAgrd_pts_in)</code> gives the follwoing error message:</p>
  <blockquote>
  <p>Error in .subset2(x, i, exact = exact) : subscript out of bounds</p>
  </blockquote>
  <p>and when I want to use the following line in autokriging also gives error message</p>
  <pre><code>krigLL12_fit &lt;- autoKrige(percent~1, SA.grid, LL12spdf) # percent is the variable of interest in the spdf LL12spdf
  </code></pre>
  <p>error message:</p>
  <blockquote>
  <p>Error in autoKrige(percent ~ 1, SA.grid, LL12spdf) :
  Either input_data or new_data is in LongLat, please reproject.
  input_data:  +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs
  new_data:    NA
  In addition: Warning messages:
  1: In proj4string(input_data) :
  CRS object has comment, which is lost in output
  2: In proj4string(input_data) :
  CRS object has comment, which is lost in output
  3: In showSRID(uprojargs, format = &quot;PROJ&quot;, multiline = &quot;NO&quot;) :
  Discarded datum Unknown based on WGS84 ellipsoid in CRS definition,
  but +towgs84= values preserved</p>
  </blockquote>
  <p>I am very new in this topic and cannot realize what I need to do, or what to correct, the coordinate units look the same in the grid and in the data file. I also fitted an autovariogram and tried to use in in autokrige but it doean't work either. thnx.</p>