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

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Oct 26, 2020 at 6:12

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$"
answered Oct 26, 2020 at 6:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.