Extracting initials with R Playing around in R with a Edx CS50 homework. The job is meant to be done in C, I am using (the more familiar) R just for warmup.

I mainly wonder whether I am breaking any good practice/style norms overall or in any tiny detail.

initials &lt;- function(full.name) {
  # Returns initials of a full name
  # Input will contain only letters (uppercase and/or lowercase) plus 
  # single spaces between words. Folks like Joseph Gordon-Levitt, 
  # Conan O’Brien, and David J. Malan won’t be using your program. (If only!)
  if (length(full.name) == 0) {
    stop ("Valid name please")
  } else {
    isspace  &lt;- integer(0)
    fn.split &lt;- unlist(strsplit(full.name, fixed = TRUE, split = ""))
    isspace  &lt;- which(fn.split == " ")
    init     &lt;- toupper(fn.split[c(1, (isspace+1))])
  return(paste(init, collapse = ""))
  }
}

initials("Stack Overflow")
[1] "SO"
You have a bug. length doesn't return the length of a string, but the length of a vector. The function you need is nchar.
This problem reveals that you haven't tested your program enough.
Always look for corner cases and test well.

A minor thing, but when you reach a stop statement, the rest of the function will not be executed, so you could remove the else block,
making the code more "flat", which is typically more readable.

As far as good practices go,
in R, it's generally not recommended to use return statements,
especially when there is a single point of return from the function.
So I recommend to simply omit the return statement at the end of the function.

Putting the above tips together:

initials &lt;- function(full.name) {
  # Returns initials of a full name
  # Input will contain only letters (uppercase and/or lowercase) plus 
  # single spaces between words. Folks like Joseph Gordon-Levitt, 
  # Conan O’Brien, and David J. Malan won’t be using your program. (If only!)
  if (nchar(full.name) == 0) {
    stop ("Valid name please")
  }
  isspace  &lt;- integer(0)
  fn.split &lt;- unlist(strsplit(full.name, fixed = TRUE, split = ""))
  isspace  &lt;- which(fn.split == " ")
  init     &lt;- toupper(fn.split[c(1, (isspace+1))])
  paste(init, collapse = "")
}