[R] How to pass a character string with a hyphen

Marc Schwartz m@rc_@chw@rtz @end|ng |rom me@com
Tue Nov 17 22:16:45 CET 2020


You might want to look at ?shQuote, which wraps text in single quotes, if the source text does not include them, or double quotes otherwise, as might be used in a shell setting, where you are passing arguments that may have spaces or other characters that may be evaluated.

My guess is that the API that you are passing the character vector to may be parsing/evaluating the '-' and only seeing the first part of the passed value.

So, for example:

> shQuote("xxxx-yyyy")
[1] "'xxxx-yyyy'"

See if that works.


Marc Schwartz

> On Nov 17, 2020, at 3:43 PM, Jeff Reichman <reichmanj using sbcglobal.net> wrote:
> R-Help
> How does one pass a character string containing a hyphen? I have a function
> that accesses an api if I hard code the object, for example
> key_key <- "xxxx-yyyy" 
> it works but when I pass the key  code to the function (say something like
> key_code <- code_input)  it returns only xxxx. So R is seeing a string with
> a negative operator I'm assuming
> Jeff

More information about the R-help mailing list