1

I'm trying to read multiple .asc files in R so I can perform some analyses later on them. I'm using this code:

library(raster)
list_file <- list.files ("C:\\Users\\Areej\\Documents\\Gibbon_bangladesh\\Bangladesh_Env_Vs_30s_ascii_R\\",
 pattern ".asc", full.names = T) 
gibbon <- stack(file_list)
gibbon

but it shows me unexpected token for the ".asc" part in the code

enter image description here

1 Answer 1

1

This is more of an R question than a ascii or even {raster} issue.
You wrote a badly defined pattern just as the error message responded.
You should have checked that you got a vector of filenames as a result for the second line of code. This code should fix the pattern issue:

library(raster)
list_file <- list.files ("C:\\Users\\Areej\\Documents\\Gibbon_bangladesh\\Bangladesh_Env_Vs_30s_ascii_R\\",
 pattern = "*.asc", full.names = T) 
gibbon <- stack(file_list)
gibbon

Note that you were missing a star (*) so the pattern will include all files with the .asc extension.

You can also use this pattern to be certain that the file ends with .asc:

pattern = "\\.asc$"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.