Geographic Information Systems Asked on March 14, 2021
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:UsersAreejDocumentsGibbon_bangladeshBangladesh_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
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:UsersAreejDocumentsGibbon_bangladeshBangladesh_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$"
Correct answer by Dror Bogin on March 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP