@BenBolker posted an answer as a comment, perhaps because he is hoping that you will stare at the difference between your code and his and get a Zen-moment. He also thinks, being the modest gentleman that he is, that it's too simple to warrant any upvotes. So I am feeling guilty that any upvotes are his rather than mine. I will now try to legitimately earn any upvotes.
The reason you got the error was the the install.packages function expects a character object, while you gave it the unquoted expression rattle. Ben use a single element character vector "rattle", thus conforming to the requirement of the function. Unlike some functions install.packages is not equipped to provide "non-standard evaluation` of its first argument.
R is a funny language at times with some inconsistent evaluation conventions. There are several functions where you can provide an unquoted expression and have it automatically converted to character. The list includes library, and its cousin, require, as well as help, subset, and $. These are considered "non-standard" evaluation by knowledgeable users and they can have their pitfalls in programming. The error message tells you that R tried to convert what it "thought" would be a language object, a closure (which loosely is an R and LiSP term for function) to a character and did not succeed. You can see the same error with this console interaction:
Error in as.character(mean) :
cannot coerce type 'closure' to vector of type 'character'
If you look at the library function mentioned by Ben and scroll down past the interanl function definitions you eventual get to the meachanism whereby library avoids that error:
package <- as.character(substitute(package))
This would also avoid the error I intentionally used as an example:
The substitute function is doing processing on a language element taken to be a closure and the resulting object an R "name" has an as.character method.
To be fair, it's rather confusing (I think) because functions like library() and require() try to make life easier for the user (mistakenly, I think) by allowing them to specify either a character vector or a symbol
I hope I was not being unfair in any way. I remember having exactly the same confusion when starting R. I just regretted needing to "answer" a question when you provided the insight. Oh, I get it, you want me to remove my close vote. I can try. I didn't use my imperial close powers because I couldn't find a real duplicate, despite searching.
(Copied from an answer by OP:) One more question: if you cannot install packages from CRAN and internet and you need to copy the packages locally first and install them from the zip, although this works one package at a time, but it's rather a painful manual process as you don't know what package depends on what. Is there any way to instruct "install.packages" to install the package and its dependencies from local or set the repos locally and is there any way to download all the available(or dependant packages) at the same time?