title: R terra create spatraster of day lengths for a year
body: <p>The length of daylight at a particular latitude can be found with the <code>daylength</code> function from <code>library(geosphere)</code>. The day length varies by the day of the year. Here's the function <code>daylength(lat, doy)</code>. I'd like to generate a 1/2 degree <code>spatraster</code> with 366 layers, one for each doy. The code below gets me close for one day. The coords dataframe appears to have the same structure as the example in the rast() set of examples but fails with the error and warning messages just below.</p>
  <pre><code>library(data.table)
  library(geosphere)
  library(terra)
  latVals &lt;- seq(-60, 90, 0.5)
  lonVals &lt;- seq(-180, 180, 0.5)
  
  dl_doy &lt;- data.table(NULL)
  temp &lt;- vector()
  for (j in 1:366) {
    for (i in 1:length(latVals)) {
      temp[i] &lt;- daylength(latVals[i], j)
    }
    new_name &lt;- paste0(&quot;day_&quot;, j)
    #  dl_doy[, (new_name) := .(temp)]
    dl_doy &lt;- cbind(dl_doy, temp)
  }
  setnames(dl_doy,  new = paste0(&quot;day_&quot;, seq(1, 366, 1)))
  
  coords &lt;- data.frame(x = rep(-100, length(latVals)), y = latVals)
  coords &lt;- cbind(coords, dl_doy$day_1)  
  names(coords) &lt;- c(&quot;x&quot;, &quot;y&quot;, &quot;lyr.1&quot;)
  test &lt;- rast(coords, type = &quot;xyz&quot;)
  #Error: [round] invalid extent
  #In addition: Warning message:
  #In min(dx) : no non-missing arguments to min; returning Inf
  </code></pre>