Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Authors@R: c(
person("Philip", "Chase", role="ctb"),
person("Paddy", "Tobias", role = "ctb"),
person("Michael", "Chirico", role = "ctb"),
person("William", "Sharp", role="ctb"))
person("William", "Sharp", role="ctb"),
person("Alexander", "Strübing", role="ctb"))
Maintainer: Shawn Garbett <shawn.garbett@vumc.org>
Description: Access data stored in 'REDCap' databases using the Application
Programming Interface (API). 'REDCap' (Research Electronic Data CAPture;
Expand Down
2 changes: 1 addition & 1 deletion R/docsRecordsTypedMethods.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#' Otherwise, records created or modified after this date will be returned.
#' @param date_end `POSIXct(1)` or `NULL`. Ignored if `NULL` (default).
#' Otherwise, records created or modified before this date will be returned.
#' @param csv_delimiter `character`. One of `c(",", "\t", ";", "|", "^")`. Designates the
#' @param csv_delimiter `character`. One of `c(",", ";", "\t", " ", "|", "^")`. Designates the
#' delimiter for the CSV file received from the API.
#' @param batch_size `integerish(1)` or `NULL`. When `NULL`,
#' all records are pulled. Otherwise, the records all pulled in batches of this size.
Expand Down
23 changes: 12 additions & 11 deletions R/exportDags.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@ exportDags <- function(rcon, ...){
#' @order 4
#' @export

exportDags.redcapApiConnection <- function(rcon,
exportDags.redcapApiConnection <- function(rcon,
...)
{
###################################################################
# Argument Validation ####

coll <- checkmate::makeAssertCollection()
checkmate::assert_class(x = rcon,
classes = "redcapApiConnection",

checkmate::assert_class(x = rcon,
classes = "redcapApiConnection",
add = coll)

checkmate::reportAssertions(coll)

###################################################################
# Make the API Body list ####

body <- list(content = "dag",
format = "csv",
returnFormat = "csv")

body <- list(content = "dag",
format = "csv",
returnFormat = "csv",
csvDelimiter = rcon$csv_delimiter())

###################################################################
# Call the API ####
as.data.frame(makeApiCall(rcon, body, ...))
as.data.frame(makeApiCall(rcon, body, ...), sep = rcon$csv_delimiter())
}
3 changes: 2 additions & 1 deletion R/exportFieldNames.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,6 @@ exportFieldNames.redcapApiConnection <- function(rcon,
# Make the API Call -----------------------------------------------
read.csv(text = as.character(makeApiCall(rcon, body, ...)),
na.strings = "",
stringsAsFactors = FALSE)
stringsAsFactors = FALSE,
sep = rcon$csv_delimiter())
}
5 changes: 3 additions & 2 deletions R/exportProjectInformation.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ exportProjectInformation.redcapApiConnection <- function(rcon,

body <- list(content = 'project',
format = 'csv',
returnFormat = 'csv')
returnFormat = 'csv',
csvDelimiter = rcon$csv_delimiter())

##################################################################
# Call the API
as.data.frame(makeApiCall(rcon, body, ...))
as.data.frame(makeApiCall(rcon, body, ...), sep = rcon$csv_delimiter())
}
7 changes: 4 additions & 3 deletions R/exportRecordsTyped.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exportRecordsTyped.redcapApiConnection <-
filter_empty_rows = TRUE,
warn_zero_coded = TRUE,
...,
csv_delimiter = ",",
csv_delimiter = rcon$csv_delimiter(),
batch_size = 100L)
{
logEvent("INFO", call='exportRecordsTyped',
Expand Down Expand Up @@ -112,7 +112,7 @@ exportRecordsTyped.redcapApiConnection <-
add = coll)

csv_delimiter <- checkmate::matchArg(x = csv_delimiter,
choices = c(",", "\t", ";", "|", "^"),
choices = c(",", ";", "\t", " ", "|", "^"),
.var.name = "csv_delimiter",
add = coll)

Expand Down Expand Up @@ -682,7 +682,8 @@ exportRecordsTyped.redcapOfflineConnection <- function(rcon,
record_response <- makeApiCall(rcon,
body = c(list(content = "record",
format = "csv",
outputFormat = "csv"),
outputFormat = "csv",
csvDelimiter = rcon$csv_delimiter()),
vectorToApiBodyList(target_field,
"fields")),
log=FALSE,
Expand Down
2 changes: 1 addition & 1 deletion R/exportReportsTyped.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exportReportsTyped.redcapApiConnection <- function(rcon,
add = coll)

csv_delimiter <- checkmate::matchArg(x = csv_delimiter,
choices = c(",", "\t", ";", "|", "^"),
choices = c(",", ";", "\t", " ", "|", "^"),
.var.name = "csv_delimiter",
add = coll)

Expand Down
2 changes: 1 addition & 1 deletion R/importDags.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ importDags.redcapApiConnection <- function(rcon,
action = "import",
format = "csv",
returnFormat = "csv",
data = writeDataForImport(data))
data = writeDataForImport(data, csv_delimiter = rcon$csv_delimiter()))

###################################################################
# Call the API ####
Expand Down
16 changes: 15 additions & 1 deletion R/redcapConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ redcapConnection <- function(url = getOption('redcap_api_url'),
length.out = rtry)
rtry_q <- retry_quietly

# CSV delimiter state for this connection -------------------------
csv_delim <- ","

getter <- function(export, ...){
switch(export,
"metadata" = exportMetaData(rc),
Expand Down Expand Up @@ -397,9 +400,20 @@ redcapConnection <- function(url = getOption('redcap_api_url'),
len = 1,
any.missing = FALSE)
rtry_q <<- rq
}
},

set_csv_delimiter = function(d) {
checkmate::assert_choice(
x = d,
choices = c(",", ";", "\t", " ", "|", "^")
)
csv_delim <<- d
},
csv_delimiter = function() csv_delim
)
class(rc) <- c("redcapApiConnection", "redcapConnection")
# Initialize csv_delimiter with default
rc$set_csv_delimiter(",")
rc
}

Expand Down
17 changes: 11 additions & 6 deletions R/writeDataForImport.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#' of a CSV for import through the API.
#'
#' @param data `data.frame` to be imported to the API
#'
#' @param csv_delimiter `character(1)` Delimiter used to separate fields in the generated CSV
#' string. Defaults to `","`.
#'

writeDataForImport <- function(data){
writeDataForImport <- function(data, csv_delimiter = ","){
coll <- checkmate::makeAssertCollection()

checkmate::assert_data_frame(x = data,
Expand All @@ -17,10 +19,13 @@ writeDataForImport <- function(data){

output <-
utils::capture.output(
utils::write.csv(data,
file = "",
na = "",
row.names = FALSE)
utils::write.table(data,
file = "",
sep = csv_delimiter,
na = "",
row.names = FALSE,
col.names = TRUE,
qmethod = "double")
)

paste0(output, collapse = "\n")
Expand Down
4 changes: 2 additions & 2 deletions man/recordsTypedMethods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/redcapAPI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/writeDataForImport.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading