title: Check if a file exists on Amazon s3 through R on EC2 instance?
body: <p>I am trying to check if a file exists on s3 through Rstudio on Amazon EC2 instance. Base R's <code>exists()</code> function and <code>file.exists()</code> functions are returning <code>FALSE</code> for every file. Following is my code, <code>exists.type</code> exists in s3 and <code>not_exists.type</code> does not exist.</p>
  
  <pre><code>library("aws.s3")
  Sys.setenv("AWS_ACCESS_KEY_ID" = "key1",
             "AWS_SECRET_ACCESS_KEY" = "key2",
             "AWS_DEFAULT_REGION" = "key3"
  )
  
  existing_file_path = "s3://bucket_name/folder_name/exists.type"
  not_existing_file_path = "s3://bucket_name/folder_name/not_exists.type"
  
  exists(existing_file_path) #returns FALSE
  exists(not_existing_file_path) #returns FALSE
  
  file.exists(existing_file_path) returns FALSE
  file.exists(not_existing_file_path) returns FALSE
  
  aws.s3::get_object(existing_file_path) #reads the entire file
  aws.s3::get_object(not_existing_file_path) #gives error
  </code></pre>
  
  <p>I tried <code>list.files</code> also, it returns <code>character(0)</code>.</p>