implementing Agent in R