0

When I input the following paste command:

rdsfile<-paste("Eobs","tmean","_81_10.rds",sep="")

I get: "Eobstmean_81_10.rds"

When I change the equals sign to the arrow usually used in R:

rdsfile<-paste("Eobs","tmean","_81_10.rds",sep<-"")

I get: "Eobs tmean _81_10.rds " (Note the space between "Eobs" and "tmean" and again between "tmean" and "_81_10.rds"

What is causing this to happen?

matlabcat
  • 172
  • 2
  • 12

1 Answers1

3

Parameters in functions should be assigned with an equals sign as in your first example so that you get your desired output.

What you are doing in your second example is to create a global object called sep with value "". You can easily check this by looking into your environment. Or simply type sep into the console.

But this global object sep is not used in the paste function, so the paste function falls back to its default, which is using a space (" ") as the separator.

Long story short: don't use <- for parameter assignments in functions.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
deschen
  • 10,012
  • 3
  • 27
  • 50