Codes for R study