suh@rto_@@ggo@o m@iii@g oii y@hoo@com
2020-May-01 03:05 UTC
[Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""
Without 'collapse', 'paste' pastes (concatenates) its arguments elementwise (separated by 'sep', " " by default). New in R devel and R patched, specifying recycle0 = FALSE makes mixing zero-length and nonzero-length arguments results in length zero. The result of paste(n, "th", sep = "", recycle0 = FALSE) always have the same length as 'n'. Previously, the result is still as long as the longest argument, with the zero-length argument like "". If all og the arguments have length zero, 'recycle0' doesn't matter. As far as I understand, 'paste' with 'collapse' as a character string is supposed to put together elements of a vector into a single character string. I think 'recycle0' shouldn't change it. In current R devel and R patched, paste(character(0), collapse = "", recycle0 = FALSE) is character(0). I think it should be "", like paste(character(0), collapse=""). paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE) is "4th, 5th". paste(c("4" ), "th", sep = "", collapse = ", ", recycle0 = FALSE) is "4th". I think paste(c( ), "th", sep = "", collapse = ", ", recycle0 = FALSE) should be "", not character(0).
Martin Maechler
2020-May-02 15:09 UTC
[Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""
>>>>> suharto anggono--- via R-devel >>>>> on Fri, 1 May 2020 03:05:37 +0000 (UTC) writes:> Without 'collapse', 'paste' pastes (concatenates) its arguments elementwise (separated by 'sep', " " by default). New in R devel and R patched, specifying recycle0 = FALSE makes mixing zero-length and nonzero-length arguments results in length zero. That's not intended. (It's what should only happen with the new (non-default) recycle0=TRUE )> The result of paste(n, "th", sep = "", recycle0 = FALSE) always have the same length as 'n'. Previously, the result is still as long as the longest argument, with the zero-length argument like "". If all og the arguments have length zero, 'recycle0' doesn't matter.> As far as I understand, 'paste' with 'collapse' as a character string is supposed to put together elements of a vector into a single character string. I think 'recycle0' shouldn't change it. Well, not quite: only 'recycle0=FALSE' shouldn't change it .. maybe this is what you meant anyway. > In current R devel and R patched, paste(character(0), collapse = "", recycle0 = FALSE) is character(0). I think it should be "", like paste(character(0), collapse=""). Definitely: The intent of the new 'recycle0' argument is to provide a non-default possibility for paste(...., recycle0=TRUE) to behave more like "arithmetic" functions where the recycling rules ensure that if one argument has length 0 then the result has length 0: i.e., paste(a,b,c,d, recycle0=TRUE) should recycle the same as a+b+c+d does recycle Indeed, the default 'recycle0=FALSE' should correspond to previous (R <= 4.0.0) behavior entirely. BUT from all I see, R-devel and R-patched's version of paste() do behave as they should. Also what you clim here is not true : > paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE) > is > "4th, 5th". > paste(c("4" ), "th", sep = "", collapse = ", ", recycle0 = FALSE) > is > "4th". > I think > paste(c( ), "th", sep = "", collapse = ", ", recycle0 = FALSE) > should be > "", > not character(0). Rather, what I see is what the comments of the following code lines claim (according to the intention of 'recycle0', contrary some of your claims above) : paste(character(0), collapse = "", recycle0 = FALSE) # is "", like paste(character(0), collapse = "") paste(character(0), collapse = "", recycle0 = TRUE) # is character(0) paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE) # is "4th, 5th" paste(c("4" ), "th", sep = "", collapse = ", ", recycle0 = FALSE) # is "4th" paste(c( ), "th", sep = "", collapse = ", ", recycle0 = FALSE) # is "th" ## paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = TRUE) # is "4th, 5th" paste(c("4" ), "th", sep = "", collapse = ", ", recycle0 = TRUE) # is "4th" paste(c( ), "th", sep = "", collapse = ", ", recycle0 = TRUE) # is character(0) There must be a lapsus / misunderstanding somewhere. I don't see any problem in the new behavior for now. Best regards, Martin
suh@rto_@@ggo@o m@iii@g oii y@hoo@com
2020-May-03 08:54 UTC
[Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""
I was wrong, as I didn't actually try and didn't read the documentation carefully. I thought that ' zero-length arguments being recycled to "" ' happens when recycle0 = TRUE. It is actually the opposite. Everywhere in my previous message, recycle0 = FALSE should be recycle0 = TRUE. I really think that 'paste' with 'collapse' specified (as a character string) should always result in a single character string, no matter what value of 'recycle0'. paste(character(0), collapse = "", recycle0 = TRUE) # character(0), but should be "" paste(character(0), recycle0 = FALSE) is the same as paste(character(0), recycle0 = TRUE) . 'recycle0' doesn't matter there. Why should paste(character(0), collapse = "", recycle0 = FALSE) be different from paste(character(0), collapse = "", recycle0 = TRUE) ? paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 =? TRUE) # "4th, 5th" paste(c("4"? ? ), "th", sep = "", collapse = ", ", recycle0 =? TRUE) # "4th" paste(c(? ? ? ? ), "th", sep = "", collapse = ", ", recycle0 =? TRUE) # character(0), but should be "" On Saturday, 2 May 2020, 10:09:21 pm GMT+7, Martin Maechler <maechler at stat.math.ethz.ch> wrote:>>>>> suharto anggono--- via R-devel >>>>>? ? on Fri, 1 May 2020 03:05:37 +0000 (UTC) writes:? ? > Without 'collapse', 'paste' pastes (concatenates) its arguments elementwise (separated by 'sep', " " by default). New in R devel and R patched, specifying recycle0 = FALSE makes mixing zero-length and nonzero-length arguments results in length zero. That's not intended. (It's what should only happen with the new (non-default) recycle0=TRUE )> The result of paste(n, "th", sep = "", recycle0 = FALSE) always have the same length as 'n'. Previously, the result is still as long as the longest argument, with the zero-length argument like "". If all og the arguments have length zero, 'recycle0' doesn't matter.? ? > As far as I understand, 'paste' with 'collapse' as a character string is supposed to put together elements of a vector into a single character string. I think 'recycle0' shouldn't change it. Well, not quite:? only? 'recycle0=FALSE'? shouldn't change it .. maybe this is what you meant anyway. ? ? > In current R devel and R patched, paste(character(0), collapse = "", recycle0 = FALSE) is character(0). I think it should be "", like paste(character(0), collapse=""). Definitely:? The intent of the new 'recycle0' argument is to provide a non-default possibility for paste(...., recycle0=TRUE) to behave more like "arithmetic" functions where the recycling rules ensure that if one argument has length 0 then the result has length 0: i.e.,? paste(a,b,c,d,? recycle0=TRUE)? ? ? should recycle the same as ? ? ? ? ? ? ? a+b+c+d? ? ? ? ? ? ? ? ? ? ? does recycle Indeed, the default 'recycle0=FALSE'? should correspond to previous (R <= 4.0.0) behavior entirely. BUT from all I see, R-devel and R-patched's version of paste() do behave as they should.? Also what you clim here is not true : ? ? > paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE) ? ? > is ? ? > "4th, 5th". ? ? > paste(c("4"? ? ), "th", sep = "", collapse = ", ", recycle0 = FALSE) ? ? > is ? ? > "4th". ? ? > I think ? ? > paste(c(? ? ? ? ), "th", sep = "", collapse = ", ", recycle0 = FALSE) ? ? > should be ? ? > "", ? ? > not character(0). Rather, what I see is what the comments of the following code lines claim (according to the intention of 'recycle0', contrary some of your claims above) : paste(character(0), collapse = "", recycle0 = FALSE) # is "", like paste(character(0), collapse = "") paste(character(0), collapse = "", recycle0 =? TRUE) # is character(0) paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE) # is "4th, 5th" paste(c("4"? ? ), "th", sep = "", collapse = ", ", recycle0 = FALSE) # is "4th" paste(c(? ? ? ? ), "th", sep = "", collapse = ", ", recycle0 = FALSE) # is "th" ## paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 =? TRUE) # is "4th, 5th" paste(c("4"? ? ), "th", sep = "", collapse = ", ", recycle0 =? TRUE) # is "4th" paste(c(? ? ? ? ), "th", sep = "", collapse = ", ", recycle0 =? TRUE) # is character(0) There must be a lapsus / misunderstanding somewhere. I don't see any problem in the new behavior for now. Best regards, Martin [[alternative HTML version deleted]]
William Dunlap
2020-May-15 17:34 UTC
[Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""
I agree: paste(collapse="something", ...) should always return a single character string, regardless of the value of recycle0. This would be similar to when there are no non-NULL arguments to paste; collapse="." gives a single empty string and collapse=NULL gives a zero long character vector.> paste()character(0)> paste(collapse=", ")[1] "" Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Apr 30, 2020 at 9:56 PM suharto_anggono--- via R-devel < r-devel at r-project.org> wrote:> Without 'collapse', 'paste' pastes (concatenates) its arguments > elementwise (separated by 'sep', " " by default). New in R devel and R > patched, specifying recycle0 = FALSE makes mixing zero-length and > nonzero-length arguments results in length zero. The result of paste(n, > "th", sep = "", recycle0 = FALSE) always have the same length as 'n'. > Previously, the result is still as long as the longest argument, with the > zero-length argument like "". If all og the arguments have length zero, > 'recycle0' doesn't matter. > > As far as I understand, 'paste' with 'collapse' as a character string is > supposed to put together elements of a vector into a single character > string. I think 'recycle0' shouldn't change it. > > In current R devel and R patched, paste(character(0), collapse = "", > recycle0 = FALSE) is character(0). I think it should be "", like > paste(character(0), collapse=""). > > paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE) > is > "4th, 5th". > paste(c("4" ), "th", sep = "", collapse = ", ", recycle0 = FALSE) > is > "4th". > I think > paste(c( ), "th", sep = "", collapse = ", ", recycle0 = FALSE) > should be > "", > not character(0). > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
Hervé Pagès
2020-May-15 18:04 UTC
[Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""
Totally agree with that. H. On 5/15/20 10:34, William Dunlap via R-devel wrote:> I agree: paste(collapse="something", ...) should always return a single > character string, regardless of the value of recycle0. This would be > similar to when there are no non-NULL arguments to paste; collapse="." > gives a single empty string and collapse=NULL gives a zero long character > vector. >> paste() > character(0) >> paste(collapse=", ") > [1] "" > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > > On Thu, Apr 30, 2020 at 9:56 PM suharto_anggono--- via R-devel < > r-devel at r-project.org> wrote: > >> Without 'collapse', 'paste' pastes (concatenates) its arguments >> elementwise (separated by 'sep', " " by default). New in R devel and R >> patched, specifying recycle0 = FALSE makes mixing zero-length and >> nonzero-length arguments results in length zero. The result of paste(n, >> "th", sep = "", recycle0 = FALSE) always have the same length as 'n'. >> Previously, the result is still as long as the longest argument, with the >> zero-length argument like "". If all og the arguments have length zero, >> 'recycle0' doesn't matter. >> >> As far as I understand, 'paste' with 'collapse' as a character string is >> supposed to put together elements of a vector into a single character >> string. I think 'recycle0' shouldn't change it. >> >> In current R devel and R patched, paste(character(0), collapse = "", >> recycle0 = FALSE) is character(0). I think it should be "", like >> paste(character(0), collapse=""). >> >> paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE) >> is >> "4th, 5th". >> paste(c("4" ), "th", sep = "", collapse = ", ", recycle0 = FALSE) >> is >> "4th". >> I think >> paste(c( ), "th", sep = "", collapse = ", ", recycle0 = FALSE) >> should be >> "", >> not character(0). >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Ddevel&d=DwICAg&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=776IovW06eUHr1EDrabHLY7F47rU9CCUEItSDI96zc0&s=xN84DhkZeoxzn6SG0QTMpOGg2w_ThmjZmZymGUuD0Uw&e>> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Ddevel&d=DwICAg&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=776IovW06eUHr1EDrabHLY7F47rU9CCUEItSDI96zc0&s=xN84DhkZeoxzn6SG0QTMpOGg2w_ThmjZmZymGUuD0Uw&e>-- Herv? Pag?s Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M1-B514 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpages at fredhutch.org Phone: (206) 667-5791 Fax: (206) 667-1319
Reasonably Related Threads
- paste(character(0), collapse="", recycle0=FALSE) should be ""
- paste(character(0), collapse="", recycle0=FALSE) should be ""
- paste(character(0), collapse="", recycle0=FALSE) should be ""
- paste(character(0), collapse="", recycle0=FALSE) should be ""
- paste(character(0), collapse="", recycle0=FALSE) should be ""