train, trainControl function not working.

I think I might be doing something fundamentally wrong. When I run a script in rStudio I put the cursor at the top and hit run on each line. Sometimes I have issues when running on an install.packages(somePackage) line. I will get a prompt asking if I want to restart rStudio, I'll hit yes, but it seem to get stuck in a loop asking me to restart over and over again. So what I do now is, under the packages tab in the user library, I just check each package I want and then run the library(somePackage) command.

Is all of this okay, or should I be doing it a different way?

Thanks