install.R 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #' Installation Helper for Docker Engine
  2. #'
  3. #' This function guides you to install Docker (Engine).
  4. #'
  5. #' @export install_docker
  6. #'
  7. #' @importFrom utils browseURL
  8. #'
  9. #' @return NULL
  10. #'
  11. #' @references \url{https://docs.docker.com/engine/installation/}
  12. #'
  13. #' @examples
  14. #' \dontrun{
  15. #' install_docker()}
  16. install_docker = function() {
  17. ostype = check_os()
  18. url_mac = 'https://docs.docker.com/docker-for-mac/install/'
  19. url_win = 'https://docs.docker.com/docker-for-windows/install/'
  20. url_lnx = 'https://docs.docker.com/engine/installation/#server'
  21. if (ostype == 'mac') {
  22. cat('Please follow the instructions on',
  23. url_mac, '\nto install Docker for Mac (admin privileges required).')
  24. browseURL(url_mac)
  25. }
  26. if (ostype == 'win') {
  27. cat('Please follow the instructions on',
  28. url_win, '\nto install Docker for Windows (admin privileges required).')
  29. browseURL(url_win)
  30. }
  31. if (ostype == 'lnx') {
  32. cat('Please follow the instructions on',
  33. url_lnx, '\nto install Docker for your Linux distribution (admin privileges required).')
  34. browseURL(url_lnx)
  35. }
  36. cat('\nPlease use check_docker() after installation to see if Docker was detectable.')
  37. invisible()
  38. }
  39. #' Check if Docker was Installed
  40. #'
  41. #' This function checks if Docker was properly
  42. #' installed and discoverable by R and liftr.
  43. #' If still not usable, please start Docker daemon
  44. #'
  45. #' @export check_docker_install
  46. #'
  47. #' @return \code{TRUE} if Docker was deteted, \code{FALSE} otherwise.
  48. #'
  49. #' @examples
  50. #' \dontrun{
  51. #' check_docker_install()}
  52. check_docker_install = function() {
  53. x = system('docker -v', intern = TRUE)
  54. if (grepl('Docker version', x)) TRUE else FALSE
  55. }
  56. #' Check if Docker Daemon is Running
  57. #'
  58. #' This function checks if the Docker daemon is running.
  59. #'
  60. #' @export check_docker_running
  61. #'
  62. #' @return \code{TRUE} if Docker daemon is running, \code{FALSE} otherwise.
  63. #'
  64. #' @examples
  65. #' \dontrun{
  66. #' check_docker_running()}
  67. check_docker_running = function() {
  68. if (!check_docker_install()) FALSE else suppressWarnings(
  69. x <- system('docker info', intern = TRUE, ignore.stderr = TRUE))
  70. length(x) != 0
  71. }