Simplifying HTML and R function