Skip to content

Commit

Permalink
Fixes #115 Incorrect download URL for getQuantityTable()
Browse files Browse the repository at this point in the history
  • Loading branch information
akbertram committed Dec 27, 2023
1 parent a7b45ae commit ceb4722
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: activityinfo
Type: Package
Title: R interface to ActivityInfo.org, an information management software for
humanitarian and development operations.
Version: 4.35
Version: 4.35.1
Date: 2023-05-25
Authors@R: c(
person("Alex", "Bertram", email = "[email protected]",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

## [4.35.1]
- Fix for `getQuantityTable()` (#115)

## [4.35]
- addForm() now respects folderId argument (#93)
- Add "bulk_delete", "manage_translations", and "reviewer_only" arguments to permissions (#91)
Expand Down
4 changes: 2 additions & 2 deletions R/extractLong.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param folderId (optional) the id of the folder or form to include. If omitted, the whole database will be included in the export.
#' @param includeBlanks if TRUE, the export will include a row for quantity fields with blank values. Default is FALSE.
#' @return a single data.frame with quantity values in rows, and dimensions in columns.
#' @importFrom httr GET write_disk
#' @importFrom httr GET write_disk modify_url
#' @importFrom utils read.table
#' @export
getQuantityTable <- function(databaseId = NA, folderId, includeBlanks = FALSE) {
Expand All @@ -28,7 +28,7 @@ getQuantityTable <- function(databaseId = NA, folderId, includeBlanks = FALSE) {
))

tempFile <- tempfile()
downloadUrl <- paste(activityInfoRootUrl(), status$result$downloadUrl, sep="/")
downloadUrl <- modify_url(activityInfoRootUrl(), path=status$result$downloadUrl)

GET(downloadUrl, write_disk(tempFile, overwrite=TRUE), activityInfoAuthentication())

Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-export.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
testthat::test_that("getQuantityTable() works", {
dbTest <- addDatabase("Reporting DB")
form <- addForm(formSchema(
dbTest$databaseId,
label = "Activities",
elements = list(textFieldSchema("Province", code = "PROVINCE", key = TRUE),
quantityFieldSchema("Nb of families", code = "FAM"),
quantityFieldSchema("Nb of clinics", code = "CLINICS"))))

addRecord(formId = form$id, fieldValues = list(PROVINCE = "North", FAM = 1012, CLINICS = 5))
addRecord(formId = form$id, fieldValues = list(PROVINCE = "South", FAM = 4445, CLINICS = 13))

quantityTable <- getQuantityTable(databaseId = dbTest$databaseId)
assertthat::assert_that(nrow(quantityTable) == 4)
})

0 comments on commit ceb4722

Please sign in to comment.