Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

54 lines
1.9KB

  1. #' Install gathertweet exectuable script
  2. #'
  3. #' Installs the `gatherwteet` executable script to the location. Should work
  4. #' with Unix and MacOS out of the box, but I can't make any guarantees about
  5. #' Windows.
  6. #'
  7. #' @param location Where to install the gathertweet executable script
  8. #' @export
  9. install_gathertweet <- function(
  10. location = "/usr/local/bin"
  11. ) {
  12. only_know_unix()
  13. if (!dir_exists(location)) {
  14. log_fatal("Location {location} does not exist, please create it and try again.")
  15. }
  16. if (!fs::file_access(location, "write")) {
  17. log_fatal("You do not have write permissions for {location}\n",
  18. "Try installing gathertweet to a local directory, such as $HOME/.local/bin")
  19. }
  20. log_info("Creating link to gathertweet at {location}/gathertweet")
  21. fs::link_create(
  22. system.file("gathertweet.R", package = "gathertweet"),
  23. path(location, "gathertweet")
  24. )
  25. instructions_run_gathertweet(location)
  26. }
  27. only_know_unix <- function() {
  28. if (.Platform$OS.type == "unix") return(invisible(TRUE))
  29. msg <- glue::glue(
  30. "I'm sorry, but I don't know how to install executable scripts on your ",
  31. "platform ({.Platform$OS.type}), so you'll have to do this manually. ",
  32. "Copy the gathertweet executable script from the location below ",
  33. "to a place where you can run it.\n",
  34. "{system.file('gathertweet.R', package='gathertweet')}"
  35. )
  36. rlang::abort(msg)
  37. }
  38. instructions_run_gathertweet <- function(location) {
  39. which_gathertweet <- tryCatch(
  40. system2("which", "gathertweet2", stdout = TRUE),
  41. error = function(e) "",
  42. warning = function(w) ""
  43. )
  44. if (which_gathertweet == "") {
  45. log_warn("{location} may not be in your system's PATH")
  46. log_warn("You may need to fully specify `{location}/gathertweet` to run gathertweet")
  47. } else {
  48. log_info("You can now call gathertweet from the command line")
  49. }
  50. log_info("In CRON jobs, use `{location}/gathertweet`")
  51. }