Q:

Why does sample() not work for a single number?

sample(x,n) The parameters are the vector, and how many times you wish to sample
sample(c(5,9),1) returns either 5 or 9

however,
sample(5,1) returns 1,2,3,4, or 5?

I've read the help section: 

If x has length 1, is numeric (in the sense of is.numeric) and x >= 1,
  sampling via sample takes place from 1:x. Note that this convenience
  feature may lead to undesired behaviour when x is of varying length in
  calls such as sample(x). See the examples.

But is there a way to make it not do this? Or do I just need to include an if statement to avoid this.

A:

Or do I just need to include an if statement to avoid this.

Yeah, unfortunately. Something like this:
result = if(length(x) == 1) {x} else {sample(x, ...)}

