title: R: multiline shell command with embedded quotes
body: <p>Seems like this should be very simple, but I cannot get it to work. I have a long shell command that I would like to span over multiple lines, but escaping the single/double quotes correctly is giving me trouble. I have searched SO and googled this, but cannot find the solution.</p>
  
  <p>Original, working code:</p>
  
  <pre><code>getVersion &lt;- function() {
      version &lt;- shell("powershell -Command $path = 'C:/Windows/notepad.exe'; $versioninfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path); $itemproperties= get-childitem $path; [pscustomobject]@{'File version' = $versioninfo.FileVersion}", intern = TRUE)
      version &lt;- gsub(" ", "", version[4])
      return(version)
  }
  </code></pre>
  
  <p>Does not work:</p>
  
  <pre><code>getVersion &lt;- function() {
      version &lt;- shell(paste0(\""powershell -Command $path = 'C:/Windows/notepad.exe'; $versioninfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path);\",
          \"$itemproperties= get-childitem $path; [pscustomobject]@{'File version' = $versioninfo.FileVersion}"\"), intern = TRUE)
      version &lt;- gsub(" ", "", version[4])
      return(version)
  }
  </code></pre>
  
  <p>Also tried this:</p>
  
  <pre><code>getVersion &lt;- function() {
      version &lt;- paste0('shell(\"powershell -Command $path = "C:/Windows/notepad.exe"; $versioninfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path);',
              '$itemproperties= get-childitem $path; [pscustomobject]@{"File version" = $versioninfo.FileVersion}\", intern = TRUE)')
              version &lt;- gsub(" ", "", version[4])
              return(version)
  }
  </code></pre>