Skip to content

Commit a5a398e

Browse files
Take two for as.POSIXct() on R (< 4.3.0)
1 parent 740cc9c commit a5a398e

File tree

8 files changed

+14
-19
lines changed

8 files changed

+14
-19
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: future.p2p
22
Title: A Peer-to-Peer Compute Cluster via Futureverse
3-
Version: 0.3.0-9030
3+
Version: 0.3.0-9031
44
Description: Implementation of the 'Future' API <doi:10.32614/RJ-2021-048> that resolves futures on a peer-to-peer ('P2P') compute environment. By using this future backend, you and your friends can share your spare compute resources with each other.
55
Imports:
66
future (>= 1.67.0),

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export(host_cluster)
1616
export(p2p_cluster_name)
1717
export(pico_username)
1818
export(worker)
19-
if (getRversion() < "4.3.0") S3method(as.POSIXct,numeric)
2019
importFrom(callr,r_bg)
2120
importFrom(future,Future)
2221
importFrom(future,FutureBackend)

R/001.import_future_functions.R

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,3 @@ future_supports_state_submitted <- local({
2525
.value
2626
}
2727
})
28-
29-
30-
## Backports
31-
#' @rawNamespace if (getRversion() < "4.3.0") S3method(as.POSIXct,numeric)
32-
if (getRversion() < "4.3.0") {
33-
as.POSIXct.numeric <- function(x, tz = "", origin, ...) {
34-
.POSIXct(if (missing(origin)) x else as.POSIXct(origin, tz = "GMT", ...) + x, tz)
35-
}
36-
}

R/pico_p2p.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pico_p2p_time <- function(time = Sys.time(), delta = 0) {
88
}
99

1010
now_str <- function(when = pico_p2p_time()) {
11-
when <- as.POSIXct(when)
11+
when <- as_POSIXct(when)
1212
format(when, format = "%FT%T")
1313
}
1414

@@ -412,7 +412,7 @@ pico_p2p_dispatch_future <- function(future) {
412412
update_parent("request")
413413
m <- pico_p2p_have_future(pico, future = file, duration = duration)
414414
state <- "request"
415-
request_expires <- as.POSIXct(as.numeric(m[["expires"]]))
415+
request_expires <- as_POSIXct(as.numeric(m[["expires"]]))
416416
next
417417
}
418418

@@ -440,7 +440,7 @@ pico_p2p_dispatch_future <- function(future) {
440440

441441
if (state == "request" && m[["type"]] == "offer") {
442442
## Ignore, if offer already expired
443-
if (Sys.time() > as.POSIXct(as.numeric(m[["expires"]]))) {
443+
if (Sys.time() > as_POSIXct(as.numeric(m[["expires"]]))) {
444444
if (debug) mdebug("Received expired work offer")
445445
next
446446
}
@@ -508,7 +508,7 @@ pico_p2p_dispatch_future <- function(future) {
508508

509509
if (m[["type"]] == "result") {
510510
## Ignore, if result already expired
511-
if (Sys.time() > as.POSIXct(as.numeric(m[["expires"]]))) {
511+
if (Sys.time() > as_POSIXct(as.numeric(m[["expires"]]))) {
512512
if (debug) mdebug("Receiving expired results")
513513
## FIXME: We cannot just ignore the file transfer, because then the worker will
514514
## stall forever. To do that, we need the worker coordinator to interrupt the

R/pico_username.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pico_username <- local({
4949
if (length(out) < 3) {
5050
stop(sprintf("pico_username(): Received unexpected results: [n=%s]\n%s", length(out), paste(out, collapse = "\n")))
5151
}
52-
username <<- structure(out[1], id = out[2], created_on = as.POSIXct(sub("T", " ", out[3])), class = "pico_username")
52+
username <<- structure(out[1], id = out[2], created_on = as_POSIXct(sub("T", " ", out[3])), class = "pico_username")
5353
}
5454

5555
username

R/utils-basic.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ hexpr <- function(expr, trim = TRUE, collapse = "; ", maxHead = 6L, maxTail = 3L
8989
if (trim) code <- trim(code)
9090
hpaste(code, collapse = collapse, maxHead = maxHead, maxTail = maxTail, ...)
9191
} # hexpr()
92+
93+
94+
as_POSIXct <- function(x, tz = "", origin = as.POSIXct("1970-01-01", tz = "GMT"), ...) {
95+
as.POSIXct(x, tz = tz, origin = origin, ...)
96+
}

R/utils-debug.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
now <- function(x = Sys.time(), format = "[%H:%M:%OS3] ") {
22
## format(x, format = format) ## slower
3-
format(as.POSIXlt(x, tz = ""), format = format)
3+
format(as_POSIXct(x, tz = ""), format = format)
44
}
55

66
debug_indent <- local({

R/worker.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ worker <- function(cluster = p2p_cluster_name(host = host, ssh_args = ssh_args),
109109
## List of known requests
110110
requests <- data.frame(
111111
future = character(0L),
112-
expires = as.POSIXct(NA_real_)[FALSE],
112+
expires = as_POSIXct(NA_real_)[FALSE],
113113
client = character(0L)
114114
)
115115
stop_if_not(is.data.frame(requests))
@@ -190,7 +190,7 @@ worker <- function(cluster = p2p_cluster_name(host = host, ssh_args = ssh_args),
190190
if (! m[["future"]] %in% requests[["future"]]) {
191191
request <- data.frame(
192192
future = m[["future"]],
193-
expires = as.POSIXct(as.numeric(m[["expires"]])),
193+
expires = as_POSIXct(as.numeric(m[["expires"]])),
194194
client = m[["from"]]
195195
)
196196
requests <- rbind(requests, request)

0 commit comments

Comments
 (0)