-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete method #372
Comments
Very raw suggestion (funnily I just needed it a few days ago): install.packages("httr")
remove_ids <- c(9, 10, 11)
url <- Sys.getenv("REDCAP_API_URL")
formData <-
list(
token = Sys.getenv("REDCAP_API_KEY"),
action = "delete",
content = "record"
# ,'records[0]' = '2HA9FF0A',
# 'records[1]' = '2J9YPFTE',
# 'records[2]' = '2J49KFRP'
)
i <- 0
for (id in remove_ids) {
formData[[paste0("records[", i, "]")]] <- id
i <- i + 1
}
response <- httr::POST(url, body = formData, encode = "form")
if (httr::http_error(response)) {
stop("Error in HTTP request to REDCap.")
} else {
print(httr::content(x = response, as = "text"))
} |
@joundso, thanks for thinking & working on this, I just noticed #373 in GitHub Actions that you're working on this too. I should have refreshed this report before I pushed what I was working on last night. It looks like we're about in the same place too: the single-arm deletion is working, the parameter for the multiple-arm project needs to be added. Do you want to work on that? If so, I'll step away and let you do your thing. I'll use your code, and feel free to take anything from my dev branch that you find helpful. Two things to note:
|
Hi @wibeasley - wow - great work! Sorry for interrupting/overlapping.
## Cleanup the backend in RStudio:
cat("\014") # Clears the console (imitates CTR + L)
rm(list = ls()) # Clears the Global Environment/variables/data
invisible(gc()) # Garbage collector/Clear unused RAM
records_to_delete <- sample(x = 1:1e10,
size = 1e3,
replace = FALSE)
loop_assignment <- function(vec) {
i <- 0
res <- list()
for (id in vec) {
res[[paste0("records[", i, "]")]] <- id
i <- i + 1
}
return(res)
}
name_assignment <- function(vec) {
return(stats::setNames(vec,
sprintf("records[%i]", seq_along(vec) - 1)))
}
microbenchmark::microbenchmark(loop_assignment(records_to_delete),
name_assignment(records_to_delete))
#> Unit: microseconds
#> expr min lq mean median uq
#> loop_assignment(records_to_delete) 10574.7 10855.15 11702.27 11157.45 11929.3
#> name_assignment(records_to_delete) 247.3 269.55 318.45 292.50 313.7
#> max neval
#> 18396.4 100
#> 2613.0 100 Created on 2021-11-24 by the reprex package (v2.0.1)
Unfortunately I won't be able to contribute much meaningful code in the coming days - but I will continue to follow your developments with interest! 👀 |
Cool. Thanks for the feedback, I'll take it from here. I saw things in your code that I like, and I'll try to do it so you show up in the commits. And I wouldn't worry too much about the loop/vector performance. Even though you say my way is 1sec faster, I'm guessing this delay will be dwarfed by the network latency & delete operation on MySQL. |
I'll add guard rails in a sec. ref #372
ref #372 Merge branch 'main' into dev
A recent post on an old community thread made we realize REDCapR doesn't implement the delete function. I'm kinda surprised no one has requested it.
The text was updated successfully, but these errors were encountered: