parsers.R 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. parse_from = function(from) {
  2. if (!is.null(from)) from else
  3. 'rocker/r-base:latest'
  4. }
  5. parse_maintainer = function(maintainer) {
  6. if (!is.null(maintainer)) maintainer else
  7. stop('Cannot find `maintainer` in header')
  8. }
  9. parse_email = function(email) {
  10. if (!is.null(email)) email else
  11. stop('Cannot find `email` in header')
  12. }
  13. parse_sysdeps = function(sysdeps) {
  14. if (!is.null(sysdeps))
  15. paste(readLines(system.file(
  16. 'templates/system-deps.Rmd', package = 'liftr')),
  17. paste(sysdeps, collapse = ' '), sep = ' ') else NULL
  18. }
  19. parse_texlive = function(texlive) {
  20. if (!is.null(texlive)) {
  21. if (texlive == TRUE) paste(
  22. readLines(system.file(
  23. 'templates/doc-texlive.Rmd', package = 'liftr')),
  24. collapse = '\n') else NULL
  25. } else {
  26. NULL
  27. }
  28. }
  29. # this solves https://github.com/road2stat/liftr/issues/12
  30. parse_pandoc = function(liftr_from, pandoc) {
  31. if (is_from_bioc(liftr_from) | is_from_rstudio(liftr_from)) {
  32. NULL
  33. } else {
  34. if (!is.null(pandoc)) {
  35. if (pandoc == FALSE) {
  36. NULL
  37. } else {
  38. paste(readLines(system.file(
  39. 'templates/doc-pandoc.Rmd', package = 'liftr')), collapse = '\n')
  40. }
  41. } else {
  42. paste(readLines(system.file(
  43. 'templates/doc-pandoc.Rmd', package = 'liftr')), collapse = '\n')
  44. }
  45. }
  46. }
  47. parse_cran = function(cran) {
  48. if (!is.null(cran)) {
  49. liftr_cran = quote_str(cran)
  50. tmp = tempfile()
  51. invisible(knit(
  52. input = system.file(
  53. 'templates/pkg-cran.Rmd', package = 'liftr'),
  54. output = tmp, quiet = TRUE))
  55. liftr_cran = readLines(tmp)
  56. liftr_cran
  57. } else {
  58. NULL
  59. }
  60. }
  61. parse_bioc = function(bioc) {
  62. if (!is.null(bioc)) {
  63. liftr_bioc = quote_str(bioc)
  64. tmp = tempfile()
  65. invisible(knit(
  66. input = system.file(
  67. 'templates/pkg-bioc.Rmd', package = 'liftr'),
  68. output = tmp, quiet = TRUE))
  69. liftr_bioc = readLines(tmp)
  70. liftr_bioc
  71. } else {
  72. NULL
  73. }
  74. }
  75. parse_remotes = function(remotes) {
  76. if (!is.null(remotes)) {
  77. liftr_remotes = quote_str(remotes)
  78. tmp = tempfile()
  79. invisible(knit(
  80. input = system.file(
  81. 'templates/pkg-remotes.Rmd', package = 'liftr'),
  82. output = tmp, quiet = TRUE))
  83. liftr_remotes = readLines(tmp)
  84. liftr_remotes
  85. } else {
  86. NULL
  87. }
  88. }
  89. parse_include = function(input, include) {
  90. if (!is.null(include)) {
  91. include_file_path = normalizePath(
  92. paste0(file_dir(input), '/', include))
  93. if (!file.exists(include_file_path))
  94. stop('include file does not exist')
  95. paste(readLines(include_file_path), collapse = '\n')
  96. } else {
  97. NULL
  98. }
  99. }