ccsarapas / lighthouse

Utility Functions for Lighthouse Institute Projects
https://ccsarapas.github.io/lighthouse/
Other
0 stars 0 forks source link

in_excel() for Mac OS #17

Closed mkatehart closed 3 months ago

mkatehart commented 3 months ago

in_excel() needs a Mac OS version of shell.exec(). Below is a quick and dirty solution that worked for opening a .csv file on Candace's Macbook pro M3, Mac OS 14.5 Sonoma.


 in_excel_mac <- 
  function (df, name, na = "") 
{
  csv_dir <- file.path(tempdir(), "csv")
  if (!dir.exists(csv_dir)) {
    dir.create(csv_dir)
  }
  if (missing(name)) {
    csv_path <- tempfile(tmpdir = csv_dir, fileext = ".csv")
  }
  else {
    csv_path <- file.path(csv_dir, paste0(name, ".csv"))
  }
  readr::write_excel_csv(df, csv_path, na = na)
  system2("open", csv_path)
} 
ccsarapas commented 3 months ago

Probably affects open_file() and open_location() too, as they also use shell.exec().