Joshua Zecha
Joshua Zecha

Reputation: 141

Function argument converted to date

I have a function with an argument that is a link to a file. My problem is, that even though I specify that I want to have a string here, a part of it seems to be recognized as a date. This results in a part of my string being replaced by "t-". How do I prevent this from happening?

smfunc <- function(link=as.character("T:\11-10-2017 - Folder\filename.csv"))
  {
  link
  }

smfunc()

[1] "T:\t-10-2017 - Folder\filename.csv"

Upvotes: 0

Views: 32

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 545913

How do I prevent this from happening?

Easy: this does not happen (that would be terrible). The problem is different: you forgot to escape the backslashes:

smfunc = function (link = "T:\\11-10-2017 - Folder\\filename.csv") {
    link
}

Without the escaped backslashes, '\11' is interpreted as a numeric character code (with value 11oct = 9dec, which is equivalent to the tab character '\t').

'\f', by pure chance, is a valid escape sequence equivalent to the “form feed” character. This is not the same as '\\f', i.e. a literal backslash followed by an “f”, and which is what you need.

Using as.character, incidentally, is redundant here: your value is already a character vector.

Upvotes: 2

Related Questions