title: R Script running via Windows Task Scheduler failing
body: <p>I have a couple of R scripts that I have scheduled to run via the <code>taskscheduleR</code> package. I keep getting errors on them when they run if they run.</p>
  
  <p>The first uses the <code>zip</code> package to simply zip up a couple of directories (This one I even tried moving all the files to the C drive and it still fails with the same error):</p>
  
  <pre><code># Lib Load ----
  if(!require(pacman)) install.packages("pacman")
  pacman::p_load(
      "zip"
      , "RDCOMClient"
  )
  
  # Zip Files ----
  zipr(
      zipfile = "C:\\path_to_desktop\\Code.zip"
      , files = c(
          "S:\\path_to_files\\R"
          ,"S:\\path_to_files\\SQL"
          ,"S:\\path_to_files\\VB"
          )
      , include_directories = TRUE
      )
  </code></pre>
  
  <p>I get the following error only when run via the task scheduler (works fine when I hit run):</p>
  
  <pre><code>Loading required package: pacman
  Error in zip_internal(zipfile, files, recurse, compression_level, append = FALSE,  : 
    Some files do not exist
  Calls: zipr -&gt; zip_internal
  Execution halted
  </code></pre>
  
  <p>This one just does not even run but task scheduler says it completes - I get no long from taskscheduler so I know it does not run (Runs fine when I hit run in R-Studio):</p>
  
  <pre><code># Lib Load ----
  if(!require(pacman)) install.packages("pacman")
  pacman::p_load(
      "tidyverse"
      , "dbplyr"
      , "DBI"
      , "odbc"
      , "readxl"
  )
  
  # Load Excel File ----
  df &lt;- read_excel(
          path = "G:\\Desktop Working Files\\FridayFile.xlsx"
          , sheet = "Sheet1"
      )
  
  # Make sure records are distinct
  df &lt;- df %&gt;% 
      distinct()
  
  # DB Connection ----
  db_con &lt;- dbConnect(
      odbc(),
      Driver = "SQL Server",
      Server = "server_name",
      Database = "db_name",
      Trusted_Connection = T
  )
  
  # Insert Records ----
  dbWriteTable(
      db_con
      , Id(
          schema = "smsdss"
          , table = "c_friday_file"
      )
      , df
      , overwrite = TRUE
  )
  
  # DB Disconnect
  dbDisconnect(db_con)
  
  # Clean Env
  rm(list = ls())
  </code></pre>
  
  <p>This one runs the database portion but does not write the file at the end (but it does when I hit run from R-Studio):</p>
  
  <pre><code># Lib Load ----
  if(!require(pacman)) install.packages("pacman")
  
  pacman::p_load(
      # DB Packages
      "DBI",
      "odbc",
  
      # Tidy
      "tidyverse",
      "dbplyr",
      "writexl",
  
      # Mapping Tools
      "tmaptools"
  )
  
  # Connection Obj ----
  con &lt;- dbConnect(
      odbc(),
      Driver = "SQL Server",
      Server = "server_name",
      Database = "db_name",
      Trusted_Connection = "TRUE"
  )
  
  # Tables ----
  pav &lt;- ...
  
  pdv &lt;- ...
  
  # Query ----
  geo_add &lt;- ...
  
  a &lt;- pdv ...
  
  add_geo &lt;- a %&gt;%...
  
  # Make df ----
  df &lt;- add_geo ...
  
  # Geocode File ####
  # Initialize the data frame
  geocoded &lt;- data.frame(stringsAsFactors = FALSE)
  
  # First Loop ----
  for(i in 1:nrow(origAddress)) {
      print(paste("Working on geocoding: ", origAddress$FullAddress[i]))
      … code
  }
  
  # Get Non Found Records ----
  # Get all records that were not found and geocode on city/town, state, zip
  for(i in 1:nrow(origAddress)) {
      … code
  }
  # Clean up Records ----
  geocoded &lt;- origAddress %&gt;%
      ...
  
  # Insert into tbl ----
  dbWriteTable(
      con
      , Id(
          schema = "smsdss"
          , table = "c_geocoded_address"
      )
      , geocoded
      , append = T
  )
  
  # Delete Dupes ----
  dbGetQuery(
    conn = con
    , paste0(
      "
      DELETE X ...
      "
    )
  )
  
  # DB Disconnect ----
  dbDisconnect(conn = con)
  
  # Save missing ---- this is what fails
  origAddress %&gt;%
    filter(is.na(lat)) %&gt;%
    select(Encounter, FullAddress, ZipCode, PartialAddress) %&gt;%
    write_xlsx(
      path = "S:\\path_to_file\\daily_geocode_file.xlsx"
      , col_names = T
      )
  
  # Clean env ----
  rm(list = ls())
  </code></pre>
  
  <p>Any ideas? Maybe a permissions issue?</p>