milos-agathon / deforestation-maps

Welcome to this tutorial where you'll learn how to map deforestation using Global Forest Change data (2001-2023) from GLAD. In this repo, we'll cover: 1. Fetching forest cover and tree loss data for your region of interest. 2. Reclassifying raster files into periods. 3. Creating powerful maps with tidyterra and ggplot2.
7 stars 0 forks source link

Some possible error #1

Open mcomsa opened 2 weeks ago

mcomsa commented 2 weeks ago

Thank you for the tutorial. Any idea why I am getting this error?

forest_loss_region <- terra::classify(

  • forest_region[[2]],
  • rcl = breaks
  • )

forest_loss_region <- as.factor(

  • forest_loss_region
  • ) Error in unique.default(x, nmax = nmax) : unique() applies only to vectors
milos-agathon commented 2 weeks ago

Hi, this error message suggests that the unique() function is being applied to an object that is not a vector. This typically happens when the input to as.factor() is not in the expected format. Can you check if you are working with raster files and if there is no error beforehand? Also, are you running my script or you made changes? It would be good to know your package version of terra, too. Thanks!

mcomsa commented 2 weeks ago

Hi. Thank you for your help. After I had updated the packages I succeeded in running steps 1-5. Step 6 is running without visible error but also without changing the image resulting from step 5. Any ideas? Thank you again. I am running your script, the last R version (4.4.1) from RStudio, and the last version for all packages (terra 1.7-78).