(I answer my question, thanks to @James for the comments.)
Use format.pval with the correct arguments. digits and eps are the most important.
Example:
pvalues <- c(0.99, 0.2, 0.32312, 0.0000123213, 0.002) format.pval(pv = pvalues,
format.pval returns a character vector.
So that stars use only ifelse or record a function
ifelse(pvalues < 0.05, "*", "")
source share