HenrikBengtsson / future

:rocket: R package: future: Unified Parallel and Distributed Processing in R for Everyone
https://future.futureverse.org
946 stars 82 forks source link

MS Windows: Need to work around UTF-8 issue for conditions too #576

Closed HenrikBengtsson closed 2 years ago

HenrikBengtsson commented 2 years ago

We've already fixed the following (Issue #473):

> f <- future({ cat("\u2713 Everything is OK") ; 42 })
> value(f)
✓ Everything is OK[1] 42

But it turns out this is a problem also conditions:

> f <- future({ message("\u2713 Everything is OK") ; 42 })
> value(f)
<U+2713> Everything is OK
[1] 42
> 

Not sure why, but it needs to be fixed as well.

HenrikBengtsson commented 2 years ago

Not sure why, but it needs to be fixed as well.

Turns out that contrary to cat(), message(), warning(), etc. by themselves do not support UTF-8;

> cat("\u2713 Everything is OK\n")
✓ Everything is OK
> message("\u2713 Everything is OK")
<U+2713> Everything is OK
> warning("\u2713 Everything is OK")
Warning message:
<U+2713> Everything is OK 

However, the following works

> c <- simpleMessage("\u2713 Everything is OK\n")
> message(c)
✓ Everything is OK

> str(c)
List of 2
 $ message: chr "<U+2713> Everything is OK\n"
 $ call   : NULL
 - attr(*, "class")= chr [1:3] "simpleMessage" "message" "condition"
> c
<simpleMessage: ✓ Everything is OK
> conditionMessage(c)
[1] "✓ Everything is OK\n"

The problem seems to be .makeMessage() used by message() et al.;

> msg <- .makeMessage("\u2713 Everything is OK\n")
> msg
[1] "<U+2713> Everything is OK\n"

which in turn happens because of gettext();

> gettext("\u2713 Everything is OK\n")
[1] "<U+2713> Everything is OK\n"

The above is with R 4.1.2 on MS Windows. In R-devel (4.2.0), R supports UTF-8 out of the box;

> message("\u2713 Everything is OK")
✓ Everything is OK
> gettext("\u2713 Everything is OK\n")
[1] "✓ Everything is OK\n"
HenrikBengtsson commented 2 years ago

So, the question is whether to work around this in future or not. In #473, the argument what that value(future(cat("\u2713 Everything is OK\n"))) should output the same as cat("\u2713 Everything is OK\n"), so that one was obvious. However, if we use the same argument for conditions, then value(future(message("\u2713 Everything is OK"))) already outputs the same as message("\u2713 Everything is OK"). Because this is a problem with message() et al., I argue there is nothing to fix in future.