I am new to the stars package in R, and am trying to work out how I assign new values to cells within a two dimensional stars object (a raster in raster package speak). With raster I can do as follows
> library("raster")
> library('stars')
> tif = system.file("tif/L7_ETMs.tif", package = "stars")
> ras<-brick(tif)[[2]] #create raster layer from 2nd layer of multilayer tif
> ras[1,1:5] #see first 5 values of top row of ras
[1] 56 57 52 45 52
> ras[1,1:4] <-100 #replace first 4 values of top row of ras
> ras[1,1:5]
[1] 100 100 100 100 52
According to the st_subset instructions in stars package manual, assignments follow ‘x[i]<-value’ but I am struggling to understand the use of ‘i’ in this context. My failed attempt is below, but I am hoping someone can provide a working alternative.
> tif = system.file("tif/L7_ETMs.tif", package = "stars")
> st<-read_stars(tif)[,,,2] #create raster layer from second layer of multilayer tif
> unlist(st[,1:5,1,]) #see first 5 values of top row of st
L7_ETMs.tif1 L7_ETMs.tif2 L7_ETMs.tif3 L7_ETMs.tif4 L7_ETMs.tif5
56 57 52 45 52
> st[,1:4,1,]<-100 #replace first 4 values of top row of ras
Error in `[<-.stars`(`*tmp*`, , 1:4, 1, , value = 100) :
unused arguments (alist(1:4, 1, ))
Many thanks