'syntax error near unexpected token in jupyter terminal

I write a r script below and want to run it in jupyter terminal. But it shows error:

./Rda_to_csv.r: line 1: syntax error near unexpected token `('

./Rda_to_csv.r: line 1: `folders <- list.files('TE_uncompressed/')'

I wonder why this happens and how to fix it? thanks!

folders <- list.files('TE_uncompressed/')
for(folder in folders)
  {
  files <- list.files(folder)
  files <- files[grepl(".rda", files, ignore.case=TRUE)]
  for(file in files){
    path_n_name <- paste0(folder, "/", file)
    raw_read <- load(path_n_name)
    out_path_n_name <- gsub(".rda", ".csv", path_n_name, ignore.case = T)
    write.csv(df_out, out_path_n_name,fileEncoding="UTF-8")
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source