Skip to content
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

paste documentation #138

Closed

Conversation

shannonpileggi
Copy link

No description provided.

@shannonpileggi
Copy link
Author

There is healthy discussion of paste documentation in bugzilla. In part because of some the discussion mixes effects of same length vs different length vectors (i.e., in the presence of recycling vs not). In addition, the sole zero-length input has special behavior.

Here are the cases I explored:

# no recycling; single input
paste({}, recycle0 = TRUE, collapse = NULL, sep = "|")
paste({}, recycle0 = TRUE, collapse = "&", sep = "|")
paste({}, recycle0 = FALSE, collapse = NULL, sep = "|")
paste({}, recycle0 = FALSE, collapse = "&", sep = "|")

# no recycling; two inputs
paste({}, 1, recycle0 = TRUE, collapse = NULL, sep = "|")
paste({}, 1, recycle0 = TRUE, collapse = "&", sep = "|")
paste({}, 1, recycle0 = FALSE, collapse = NULL, sep = "|")
paste({}, 1, recycle0 = FALSE, collapse = "&", sep = "|")

# recycling; two inputs
paste({}, 1:2, recycle0 = TRUE, collapse = NULL, sep = "|")
paste({}, 1:2, recycle0 = TRUE, collapse = "&", sep = "|")
paste({}, 1:2, recycle0 = FALSE, collapse = NULL, sep = "|")
paste({}, 1:2, recycle0 = FALSE, collapse = "&", sep = "|")

with results summarized as follows:
image

In order to clarify documentation, I propose

  1. Modifying the "Details" section
  2. Modifying the arguments description of recycle0
  3. Modifying the examples section

Copy link

@trangdata trangdata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 💯 I only have a minor comment.

\code{\link{character}(0)}. This argument interacts with \code{collapse}
such that under the conditions \code{recycle0} is \code{TRUE} and
\code{collapse} is not \code{NULL}, zero-length arguments instead output as
\code{""} .}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor suggestion on spacing

Suggested change
\code{""} .}
\code{""}.}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent catch, thank you so much @trangdata!

paste("The value is", val[valid], "-- not so good!")
paste("The value is", val[valid], "-- good: empty!", recycle0=TRUE) # -> character(0)
# zero length arguments recycled as `""`
paste({}, 1:2)
Copy link
Collaborator

@MichaelChirico MichaelChirico Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would prefer paste(character(), 1:2). {} is concise, but masks two behaviors:

  1. the empty expression evaluates to NULL: identical(NULL, {}) is TRUE
  2. inputs to paste() are cast with as.character(): identical(as.character(NULL), character()) is TRUE

Using character() is thus more "minimal" in the sense of demonstrating the behavior more directly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this out, @MichaelChirico!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants