Handle direction == ">" in R