addServer.R 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #' Add New Remote Server to MODIS Inventory
  2. #'
  3. #' @description
  4. #' \code{addServer} is a non-exported helper function to add a new entry to the
  5. #' list of online (FTP) servers featured by \strong{MODIS} (see
  6. #' \code{MODIS:::MODIS_FTPinfo}).
  7. #'
  8. #' @param name Character. Name of the remote server that should be added to the
  9. #' inventory.
  10. #' @param sensor Character. Sensor type, defaults to 'MODIS'.
  11. #' @param basepath Character. Absolute online server path.
  12. #' @param varpath Character. Pattern of organizational structure on server.
  13. #' @param content Character. Content type, defaults to "images".
  14. #' @param path_ext Character. Path to folder containing file
  15. #' 'MODIS_FTPinfo.RData'. When working with RStudio projects (.Rproj), this
  16. #' usually defaults to 'inst/external'.
  17. #' @param overwrite Logical. If \code{TRUE}, the initial '.RData' file located
  18. #' in 'path_ext' will be overwritten.
  19. #' @param ... Currently not used.
  20. #'
  21. #' @return
  22. #' A 'list' holding the updated contents of 'MODIS_FTPinfo.RData'.
  23. #'
  24. #' @seealso
  25. #' \code{MODIS:::MODIS_FTPinfo}.
  26. #'
  27. #' @author
  28. #' Florian Detsch
  29. #'
  30. #' @examples
  31. #' \dontrun{
  32. #' ## E.g., add server of MODIS evapotranspiration product
  33. #' MODIS:::addServer(name = "NTSG", sensor = "MODIS",
  34. #' basepath = "ftp://ftp.ntsg.umt.edu/pub/MODIS/NTSG_Products/MOD16/",
  35. #' varpath = "PRODUCT.CCC/YYYY/DDD/")
  36. #' }
  37. #'
  38. # #' @export addServer
  39. #' @name addServer
  40. addServer <- function(name, sensor = "MODIS", basepath, varpath,
  41. content = "images", path_ext = "inst/external",
  42. overwrite = FALSE, ...) {
  43. ## load list of current products
  44. load(paste0(path_ext, "/MODIS_FTPinfo.RData"))
  45. ## id of last and new entry
  46. int_id_last <- length(MODIS_FTPinfo)
  47. int_id_new <- int_id_last + 1
  48. ## add new collection
  49. ls_new <- list(list(
  50. name = name,
  51. SENSOR = sensor,
  52. basepath = basepath,
  53. variablepath = varpath,
  54. content = content
  55. ))
  56. names(ls_new) <- paste0("ftpstring", int_id_new)
  57. MODIS_FTPinfo <- append(MODIS_FTPinfo, ls_new)
  58. ## output storage
  59. if (overwrite) {
  60. file_out <- paste0(path_ext, "/MODIS_FTPinfo.RData")
  61. save(MODIS_FTPinfo, file = file_out)
  62. }
  63. ## return updated collections dataset
  64. return(MODIS_FTPinfo)
  65. }