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

Warning when trying to write non-character objects? #5

Closed
mdlincoln opened this issue Aug 30, 2015 · 2 comments
Closed

Warning when trying to write non-character objects? #5

mdlincoln opened this issue Aug 30, 2015 · 2 comments

Comments

@mdlincoln
Copy link
Owner

And should we try to handle conversion? My instinct is no - deciding how to format the printing of an object should be left to the user, this package should just handle moving that text to the clipboard.

@lmmx
Copy link
Contributor

lmmx commented Aug 30, 2015

It could warn "not a character vector, coercing to one"... but I think a clipboard handler should be quiet.

Here for example users are forced to write 'glue code', writeClipboard( as.character(x) ) when they clearly just mean writeClipboard(x). Warning might be annoying.

I think it should assume* what's passed in is either already a 1-tuple character vector, or ready to be as.character'd and paste0(collapse = sep)'d into that format [as discussed]

It would always be converted to a string by writeChar upon writing to the connection, so doing that explicitly is fine.

I made a new file, flat_str.R, defining a helper called by each of the OS-specific write_clip functions with the appropriate sep parameter

flat_str <- function(content, sep) {
  content <- as.character(content)
  if (length(content) > 1) {
    content <- paste0(content, collapse = sep)
  }
  return(content)
}

I'll push some code for you to look at in a minute anyhoo :-)

@mdlincoln
Copy link
Owner Author

It would always be converted to a string by writeChar upon writing to the connection, so doing that explicitly is fine.

This is probably the best justification for not warning anyone 👍

Closed by #7

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

No branches or pull requests

2 participants