title: Mutate when function output has data in two columns (geosphere)
body: <p>I have animal survey data from transects. Transects are divided into sections. There are lat/lon data for the start/endpoints of some sections but not others, and I want to calculate the start/endpoints for sections where these values are missing. Missing start/endpoints should be calculated using the section bearing (degrees), section length (m).</p>
  <p>Example data:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Section</th>
  <th>StartLon</th>
  <th>StartLat</th>
  <th>EndLon</th>
  <th>EndLat</th>
  <th>Bearing</th>
  <th>Length</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>-132.4053</td>
  <td>53.00704</td>
  <td>-132.4053</td>
  <td>53.00714</td>
  <td>360</td>
  <td>5</td>
  </tr>
  <tr>
  <td>2</td>
  <td>-132.4053</td>
  <td>53.00714</td>
  <td>NA</td>
  <td>NA</td>
  <td>360</td>
  <td>10</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I'm trying to use destPoint (geosphere) to calculate the missing start/endpoints (NAs). The output of destPoint looks like:</p>
  <pre><code>        lon       lat
  [1,] -132.4053 53.00701
  </code></pre>
  <p>My code:</p>
  <pre><code>data %&gt;% 
    mutate(EndLon = if_else(is.na(EndLon), destPoint(c(StartLon, StartLat), Bearing, Length), EndLon))
  
  data %&gt;% 
    mutate(EndLat = if_else(is.na(EndLat), destPoint(c(StartLon, StartLat), Bearing, Length), EndLat))
  </code></pre>
  <p>My code gives this error:</p>
  <pre><code>Error: Problem with `mutate()` input `test`.
  x Wrong length for a vector, should be 2
  i Input `test` is `if_else(...)`
  </code></pre>
  <p>I think the error is because the output of destPoint is two values (lon and lat), and the mutated column can only hold one value. Maybe there's a way to use select() so that only lon or lat goes into the mutated column?</p>
  <p>Hoping for a dplyr solution.</p>