title: Error in importing GeoTiff files - R RASTER package
body: <p>I am trying to create a loop for automatically upload some GEOTiff datasets using the raster{raster}.
  Firstly, I defined the folder where all my files are saved using the variable <code>path</code>. Then I created a loop as in the code below, where <code>crop_name</code> is a vector containing the variable part of the names of the GEOTiff datasets that I want to import.</p>
  
  <p>This is the code that I am using:</p>
  
  <pre><code>path &lt;- file.path("C:","Users","pbarbieri","Documents","Pietro","R Analysis", "Budgets test countries baseline scenario", "global", "crop prodution", "All")
  
  for (i in 1:length(crop_name)){
  
    name_file_upload &lt;-paste(crop_name[i],"_Production.tif",sep = "")
    path_2 &lt;- file.path(path, name_file_upload)
    name_file &lt;- paste(crop_name[i], "production", sep = "_")
    assign(name_file,  raster(path_2))   
  }
  </code></pre>
  
  <p>When I run the code, I get the following error message:</p>
  
  <pre><code>Error in .local(.Object, ...) : 
     `C:\Users\pbarbieri\Documents\Pietro\R Analysis\Budgets test countries baseline scenario\global\crop prodution\All\barley_Production.tif' does not exist in the file system,
     and is not recognised as a supported dataset name.
  
  Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file. (file does not exist)
  </code></pre>
  
  <p>Nevertheless, if I try to import manually one of the GEOTiff files using the same path as the one generated and saved in <code>path_2</code>, I don't get any error.
  I read that sometime the {raster} package might give problems with underscores in the datasets names, but deleting the underscores did not solve my problem. What am I doing wrong?</p>