purrr::map_int: Can't coerce element 1 from a double to a integerR formatting only for integers, removing decimalsThe difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframepurrr - use full list-elements in map callR can't install devtools or git2r due to lack of zlib on macOS 10.12.3 and 10.12.5double nesting with tidyverse and purrrERROR: compilation failed for package ‘rlang’ in rstudio - Debian jessie 8.0What happens on Ubuntu/Debian with user installed R packages during R upgradeHow to use purrr for extracting elements from a list?How to select elements with the same name from nested list with purrr?python in r: pandas not foundR purrr pmap Can't pluck from a closure
How to publish superseding results without creating enemies
What is the name of this Allen-head furniture fastener?
Why is the year in this ISO timestamp not 2019?
Planar regular languages
Why is this sentence grammatical?
How do certain apps show new notifications when internet access is restricted to them?
Why is the car dealer insisting on a loan instead of cash?
How does a simple logistic regression model achieve a 92% classification accuracy on MNIST?
Prove that a convergent real sequence always has a smallest or a largest term
What organs or modifications would be needed for a life biological creature not to require sleep?
Does a large scratch in an ND filter affect image quality?
How does a linear operator act on a bra?
Ambiguity in notation resolved by +
Where is it? - The Google Earth Challenge Ep. 3
Why is the UK still pressing on with Brexit?
How do we know that black holes are spinning?
Python web-scraper to download table of transistor counts from Wikipedia
In what state are satellites left in when they are left in a graveyard orbit?
Asked to Not Use Transactions and to Use A Workaround to Simulate One
Is the Dodge action perceptible to other characters?
Bash awk command with quotes
Why don't Wizards use wrist straps to protect against disarming charms?
Impossible Scrabble Words
How to give my students a straightedge instead of a ruler
purrr::map_int: Can't coerce element 1 from a double to a integer
R formatting only for integers, removing decimalsThe difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframepurrr - use full list-elements in map callR can't install devtools or git2r due to lack of zlib on macOS 10.12.3 and 10.12.5double nesting with tidyverse and purrrERROR: compilation failed for package ‘rlang’ in rstudio - Debian jessie 8.0What happens on Ubuntu/Debian with user installed R packages during R upgradeHow to use purrr for extracting elements from a list?How to select elements with the same name from nested list with purrr?python in r: pandas not foundR purrr pmap Can't pluck from a closure
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am having the weirdest bug with map_int from the purrr package.
# Works as expected
purrr::map_int(1:10, function(x) x)
#> [1] 1 2 3 4 5 6 7 8 9 10
# Why on earth is that not working?
purrr::map_int(1:10, function(x) 2*x)
#> Error: Can't coerce element 1 from a double to a integer
# or that?
purrr::map_int(1:10, round)
#> Error: Can't coerce element 1 from a double to a integer
Created on 2019-03-28 by the reprex package (v0.2.1)
I run 3.5.2 in rocker container (Debian) with the latest github version of everything:
sessioninfo::package_info("purrr")
#> package * version date lib source
#> magrittr 1.5.0.9000 2019-03-28 [1] Github (tidyverse/magrittr@4104d6b)
#> purrr 0.3.2.9000 2019-03-28 [1] Github (tidyverse/purrr@25d84f7)
#> rlang 0.3.2.9000 2019-03-28 [1] Github (r-lib/rlang@9376215)
#>
#> [1] /usr/local/lib/R/site-library
#> [2] /usr/local/lib/R/library
r purrr
add a comment
|
I am having the weirdest bug with map_int from the purrr package.
# Works as expected
purrr::map_int(1:10, function(x) x)
#> [1] 1 2 3 4 5 6 7 8 9 10
# Why on earth is that not working?
purrr::map_int(1:10, function(x) 2*x)
#> Error: Can't coerce element 1 from a double to a integer
# or that?
purrr::map_int(1:10, round)
#> Error: Can't coerce element 1 from a double to a integer
Created on 2019-03-28 by the reprex package (v0.2.1)
I run 3.5.2 in rocker container (Debian) with the latest github version of everything:
sessioninfo::package_info("purrr")
#> package * version date lib source
#> magrittr 1.5.0.9000 2019-03-28 [1] Github (tidyverse/magrittr@4104d6b)
#> purrr 0.3.2.9000 2019-03-28 [1] Github (tidyverse/purrr@25d84f7)
#> rlang 0.3.2.9000 2019-03-28 [1] Github (r-lib/rlang@9376215)
#>
#> [1] /usr/local/lib/R/site-library
#> [2] /usr/local/lib/R/library
r purrr
Can you try withmap_dbl
– akrun
Mar 28 at 12:23
2
The doc saysmap_lgl(), map_int(), map_dbl() and map_chr() each return an atomic vector of the indicated type (or die trying).. It seems they don't try very hard :), but I believe this is expected, you could usepurrr::map_chr(1:10, function(x) 2*x)because you'd be coercing to a more general type (i.e. conversion always works), here you would like a double to be coerced to integer (2is a double so the result is as well), andpurrr::map_intdoesn't even want to try that (it would require checking all values).
– Moody_Mudskipper
Mar 28 at 12:41
@Moody_Mudskipper As far as I am concerned, this is a bug. As you say, it is really inconsistent with all the other map function that perform an implicit conversion! Consider thatpurrr::map_df(1:10, function(x) list(a = 2*x))works. So doespurrr::map_chr(1:10, function(x) x). In my real use case, I usefloor, and having to useas.integerdefeats the whole point. You can argue that this particular cast leads to information loss but then why allow implicit casting from double to character, which causes loss of precision when casting back to numeric?
– antoine-sac
Mar 28 at 12:50
@IceCreamToucan Yes, on reflection it does make sense. Quite limiting though, considering the number of functions that return numeric values even for integers (e.g.round,floor, etc).
– antoine-sac
Mar 28 at 13:01
add a comment
|
I am having the weirdest bug with map_int from the purrr package.
# Works as expected
purrr::map_int(1:10, function(x) x)
#> [1] 1 2 3 4 5 6 7 8 9 10
# Why on earth is that not working?
purrr::map_int(1:10, function(x) 2*x)
#> Error: Can't coerce element 1 from a double to a integer
# or that?
purrr::map_int(1:10, round)
#> Error: Can't coerce element 1 from a double to a integer
Created on 2019-03-28 by the reprex package (v0.2.1)
I run 3.5.2 in rocker container (Debian) with the latest github version of everything:
sessioninfo::package_info("purrr")
#> package * version date lib source
#> magrittr 1.5.0.9000 2019-03-28 [1] Github (tidyverse/magrittr@4104d6b)
#> purrr 0.3.2.9000 2019-03-28 [1] Github (tidyverse/purrr@25d84f7)
#> rlang 0.3.2.9000 2019-03-28 [1] Github (r-lib/rlang@9376215)
#>
#> [1] /usr/local/lib/R/site-library
#> [2] /usr/local/lib/R/library
r purrr
I am having the weirdest bug with map_int from the purrr package.
# Works as expected
purrr::map_int(1:10, function(x) x)
#> [1] 1 2 3 4 5 6 7 8 9 10
# Why on earth is that not working?
purrr::map_int(1:10, function(x) 2*x)
#> Error: Can't coerce element 1 from a double to a integer
# or that?
purrr::map_int(1:10, round)
#> Error: Can't coerce element 1 from a double to a integer
Created on 2019-03-28 by the reprex package (v0.2.1)
I run 3.5.2 in rocker container (Debian) with the latest github version of everything:
sessioninfo::package_info("purrr")
#> package * version date lib source
#> magrittr 1.5.0.9000 2019-03-28 [1] Github (tidyverse/magrittr@4104d6b)
#> purrr 0.3.2.9000 2019-03-28 [1] Github (tidyverse/purrr@25d84f7)
#> rlang 0.3.2.9000 2019-03-28 [1] Github (r-lib/rlang@9376215)
#>
#> [1] /usr/local/lib/R/site-library
#> [2] /usr/local/lib/R/library
r purrr
r purrr
edited Mar 28 at 12:53
antoine-sac
asked Mar 28 at 12:21
antoine-sacantoine-sac
3,8742 gold badges16 silver badges46 bronze badges
3,8742 gold badges16 silver badges46 bronze badges
Can you try withmap_dbl
– akrun
Mar 28 at 12:23
2
The doc saysmap_lgl(), map_int(), map_dbl() and map_chr() each return an atomic vector of the indicated type (or die trying).. It seems they don't try very hard :), but I believe this is expected, you could usepurrr::map_chr(1:10, function(x) 2*x)because you'd be coercing to a more general type (i.e. conversion always works), here you would like a double to be coerced to integer (2is a double so the result is as well), andpurrr::map_intdoesn't even want to try that (it would require checking all values).
– Moody_Mudskipper
Mar 28 at 12:41
@Moody_Mudskipper As far as I am concerned, this is a bug. As you say, it is really inconsistent with all the other map function that perform an implicit conversion! Consider thatpurrr::map_df(1:10, function(x) list(a = 2*x))works. So doespurrr::map_chr(1:10, function(x) x). In my real use case, I usefloor, and having to useas.integerdefeats the whole point. You can argue that this particular cast leads to information loss but then why allow implicit casting from double to character, which causes loss of precision when casting back to numeric?
– antoine-sac
Mar 28 at 12:50
@IceCreamToucan Yes, on reflection it does make sense. Quite limiting though, considering the number of functions that return numeric values even for integers (e.g.round,floor, etc).
– antoine-sac
Mar 28 at 13:01
add a comment
|
Can you try withmap_dbl
– akrun
Mar 28 at 12:23
2
The doc saysmap_lgl(), map_int(), map_dbl() and map_chr() each return an atomic vector of the indicated type (or die trying).. It seems they don't try very hard :), but I believe this is expected, you could usepurrr::map_chr(1:10, function(x) 2*x)because you'd be coercing to a more general type (i.e. conversion always works), here you would like a double to be coerced to integer (2is a double so the result is as well), andpurrr::map_intdoesn't even want to try that (it would require checking all values).
– Moody_Mudskipper
Mar 28 at 12:41
@Moody_Mudskipper As far as I am concerned, this is a bug. As you say, it is really inconsistent with all the other map function that perform an implicit conversion! Consider thatpurrr::map_df(1:10, function(x) list(a = 2*x))works. So doespurrr::map_chr(1:10, function(x) x). In my real use case, I usefloor, and having to useas.integerdefeats the whole point. You can argue that this particular cast leads to information loss but then why allow implicit casting from double to character, which causes loss of precision when casting back to numeric?
– antoine-sac
Mar 28 at 12:50
@IceCreamToucan Yes, on reflection it does make sense. Quite limiting though, considering the number of functions that return numeric values even for integers (e.g.round,floor, etc).
– antoine-sac
Mar 28 at 13:01
Can you try with
map_dbl– akrun
Mar 28 at 12:23
Can you try with
map_dbl– akrun
Mar 28 at 12:23
2
2
The doc says
map_lgl(), map_int(), map_dbl() and map_chr() each return an atomic vector of the indicated type (or die trying).. It seems they don't try very hard :), but I believe this is expected, you could use purrr::map_chr(1:10, function(x) 2*x) because you'd be coercing to a more general type (i.e. conversion always works), here you would like a double to be coerced to integer (2 is a double so the result is as well), and purrr::map_int doesn't even want to try that (it would require checking all values).– Moody_Mudskipper
Mar 28 at 12:41
The doc says
map_lgl(), map_int(), map_dbl() and map_chr() each return an atomic vector of the indicated type (or die trying).. It seems they don't try very hard :), but I believe this is expected, you could use purrr::map_chr(1:10, function(x) 2*x) because you'd be coercing to a more general type (i.e. conversion always works), here you would like a double to be coerced to integer (2 is a double so the result is as well), and purrr::map_int doesn't even want to try that (it would require checking all values).– Moody_Mudskipper
Mar 28 at 12:41
@Moody_Mudskipper As far as I am concerned, this is a bug. As you say, it is really inconsistent with all the other map function that perform an implicit conversion! Consider that
purrr::map_df(1:10, function(x) list(a = 2*x)) works. So does purrr::map_chr(1:10, function(x) x). In my real use case, I use floor, and having to use as.integer defeats the whole point. You can argue that this particular cast leads to information loss but then why allow implicit casting from double to character, which causes loss of precision when casting back to numeric?– antoine-sac
Mar 28 at 12:50
@Moody_Mudskipper As far as I am concerned, this is a bug. As you say, it is really inconsistent with all the other map function that perform an implicit conversion! Consider that
purrr::map_df(1:10, function(x) list(a = 2*x)) works. So does purrr::map_chr(1:10, function(x) x). In my real use case, I use floor, and having to use as.integer defeats the whole point. You can argue that this particular cast leads to information loss but then why allow implicit casting from double to character, which causes loss of precision when casting back to numeric?– antoine-sac
Mar 28 at 12:50
@IceCreamToucan Yes, on reflection it does make sense. Quite limiting though, considering the number of functions that return numeric values even for integers (e.g.
round, floor, etc).– antoine-sac
Mar 28 at 13:01
@IceCreamToucan Yes, on reflection it does make sense. Quite limiting though, considering the number of functions that return numeric values even for integers (e.g.
round, floor, etc).– antoine-sac
Mar 28 at 13:01
add a comment
|
2 Answers
2
active
oldest
votes
The documentation from help(map) says
The output of .f will be automatically typed upwards , e.g. logical ->
integer -> double -> character
It appears to be following the larger ordering given in help(c). For example, this produces an error map_dbl(1:10, ~complex(real = .x, imaginary = 1)).
NULL < raw < logical < integer < double < complex < character < list <
expression
As you can see in that ordering, double-to-integer is a downward conversion. So, the function is designed to not do this kind of conversion.
The solution is to either write a function .f which outputs integer (or lower) classed objects (as in @Stéphane Laurent's answer), or just use as.integer(map(.x, .f)).
This is a kind of type-checking, which can be a useful feature for preventing programming mistakes.
add a comment
|
2*x is not an integer because 2 is not. Do instead
purrr::map_int(1:10, function(x) 2L*x)
Sure. This is just really inconsistent with all the other map function that perform an implicit conversion! "Can't coerce from a double to a integer" is really "Don't want to ...". Consider thatpurrr::map_df(1:10, function(x) list(a = 2*x))works. So doespurrr::map_chr(1:10, function(x) x). In my real use case, I usefloor, and having to useas.integerdefeats the whole point.
– antoine-sac
Mar 28 at 12:45
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397509%2fpurrrmap-int-cant-coerce-element-1-from-a-double-to-a-integer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The documentation from help(map) says
The output of .f will be automatically typed upwards , e.g. logical ->
integer -> double -> character
It appears to be following the larger ordering given in help(c). For example, this produces an error map_dbl(1:10, ~complex(real = .x, imaginary = 1)).
NULL < raw < logical < integer < double < complex < character < list <
expression
As you can see in that ordering, double-to-integer is a downward conversion. So, the function is designed to not do this kind of conversion.
The solution is to either write a function .f which outputs integer (or lower) classed objects (as in @Stéphane Laurent's answer), or just use as.integer(map(.x, .f)).
This is a kind of type-checking, which can be a useful feature for preventing programming mistakes.
add a comment
|
The documentation from help(map) says
The output of .f will be automatically typed upwards , e.g. logical ->
integer -> double -> character
It appears to be following the larger ordering given in help(c). For example, this produces an error map_dbl(1:10, ~complex(real = .x, imaginary = 1)).
NULL < raw < logical < integer < double < complex < character < list <
expression
As you can see in that ordering, double-to-integer is a downward conversion. So, the function is designed to not do this kind of conversion.
The solution is to either write a function .f which outputs integer (or lower) classed objects (as in @Stéphane Laurent's answer), or just use as.integer(map(.x, .f)).
This is a kind of type-checking, which can be a useful feature for preventing programming mistakes.
add a comment
|
The documentation from help(map) says
The output of .f will be automatically typed upwards , e.g. logical ->
integer -> double -> character
It appears to be following the larger ordering given in help(c). For example, this produces an error map_dbl(1:10, ~complex(real = .x, imaginary = 1)).
NULL < raw < logical < integer < double < complex < character < list <
expression
As you can see in that ordering, double-to-integer is a downward conversion. So, the function is designed to not do this kind of conversion.
The solution is to either write a function .f which outputs integer (or lower) classed objects (as in @Stéphane Laurent's answer), or just use as.integer(map(.x, .f)).
This is a kind of type-checking, which can be a useful feature for preventing programming mistakes.
The documentation from help(map) says
The output of .f will be automatically typed upwards , e.g. logical ->
integer -> double -> character
It appears to be following the larger ordering given in help(c). For example, this produces an error map_dbl(1:10, ~complex(real = .x, imaginary = 1)).
NULL < raw < logical < integer < double < complex < character < list <
expression
As you can see in that ordering, double-to-integer is a downward conversion. So, the function is designed to not do this kind of conversion.
The solution is to either write a function .f which outputs integer (or lower) classed objects (as in @Stéphane Laurent's answer), or just use as.integer(map(.x, .f)).
This is a kind of type-checking, which can be a useful feature for preventing programming mistakes.
edited Mar 28 at 13:21
answered Mar 28 at 13:15
IceCreamToucanIceCreamToucan
14.9k2 gold badges9 silver badges20 bronze badges
14.9k2 gold badges9 silver badges20 bronze badges
add a comment
|
add a comment
|
2*x is not an integer because 2 is not. Do instead
purrr::map_int(1:10, function(x) 2L*x)
Sure. This is just really inconsistent with all the other map function that perform an implicit conversion! "Can't coerce from a double to a integer" is really "Don't want to ...". Consider thatpurrr::map_df(1:10, function(x) list(a = 2*x))works. So doespurrr::map_chr(1:10, function(x) x). In my real use case, I usefloor, and having to useas.integerdefeats the whole point.
– antoine-sac
Mar 28 at 12:45
add a comment
|
2*x is not an integer because 2 is not. Do instead
purrr::map_int(1:10, function(x) 2L*x)
Sure. This is just really inconsistent with all the other map function that perform an implicit conversion! "Can't coerce from a double to a integer" is really "Don't want to ...". Consider thatpurrr::map_df(1:10, function(x) list(a = 2*x))works. So doespurrr::map_chr(1:10, function(x) x). In my real use case, I usefloor, and having to useas.integerdefeats the whole point.
– antoine-sac
Mar 28 at 12:45
add a comment
|
2*x is not an integer because 2 is not. Do instead
purrr::map_int(1:10, function(x) 2L*x)
2*x is not an integer because 2 is not. Do instead
purrr::map_int(1:10, function(x) 2L*x)
answered Mar 28 at 12:23
Stéphane LaurentStéphane Laurent
22.1k9 gold badges59 silver badges110 bronze badges
22.1k9 gold badges59 silver badges110 bronze badges
Sure. This is just really inconsistent with all the other map function that perform an implicit conversion! "Can't coerce from a double to a integer" is really "Don't want to ...". Consider thatpurrr::map_df(1:10, function(x) list(a = 2*x))works. So doespurrr::map_chr(1:10, function(x) x). In my real use case, I usefloor, and having to useas.integerdefeats the whole point.
– antoine-sac
Mar 28 at 12:45
add a comment
|
Sure. This is just really inconsistent with all the other map function that perform an implicit conversion! "Can't coerce from a double to a integer" is really "Don't want to ...". Consider thatpurrr::map_df(1:10, function(x) list(a = 2*x))works. So doespurrr::map_chr(1:10, function(x) x). In my real use case, I usefloor, and having to useas.integerdefeats the whole point.
– antoine-sac
Mar 28 at 12:45
Sure. This is just really inconsistent with all the other map function that perform an implicit conversion! "Can't coerce from a double to a integer" is really "Don't want to ...". Consider that
purrr::map_df(1:10, function(x) list(a = 2*x)) works. So does purrr::map_chr(1:10, function(x) x). In my real use case, I use floor, and having to use as.integer defeats the whole point.– antoine-sac
Mar 28 at 12:45
Sure. This is just really inconsistent with all the other map function that perform an implicit conversion! "Can't coerce from a double to a integer" is really "Don't want to ...". Consider that
purrr::map_df(1:10, function(x) list(a = 2*x)) works. So does purrr::map_chr(1:10, function(x) x). In my real use case, I use floor, and having to use as.integer defeats the whole point.– antoine-sac
Mar 28 at 12:45
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397509%2fpurrrmap-int-cant-coerce-element-1-from-a-double-to-a-integer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you try with
map_dbl– akrun
Mar 28 at 12:23
2
The doc says
map_lgl(), map_int(), map_dbl() and map_chr() each return an atomic vector of the indicated type (or die trying).. It seems they don't try very hard :), but I believe this is expected, you could usepurrr::map_chr(1:10, function(x) 2*x)because you'd be coercing to a more general type (i.e. conversion always works), here you would like a double to be coerced to integer (2is a double so the result is as well), andpurrr::map_intdoesn't even want to try that (it would require checking all values).– Moody_Mudskipper
Mar 28 at 12:41
@Moody_Mudskipper As far as I am concerned, this is a bug. As you say, it is really inconsistent with all the other map function that perform an implicit conversion! Consider that
purrr::map_df(1:10, function(x) list(a = 2*x))works. So doespurrr::map_chr(1:10, function(x) x). In my real use case, I usefloor, and having to useas.integerdefeats the whole point. You can argue that this particular cast leads to information loss but then why allow implicit casting from double to character, which causes loss of precision when casting back to numeric?– antoine-sac
Mar 28 at 12:50
@IceCreamToucan Yes, on reflection it does make sense. Quite limiting though, considering the number of functions that return numeric values even for integers (e.g.
round,floor, etc).– antoine-sac
Mar 28 at 13:01