My suggestion is to not write code that includes the installation of a package. That action only needs to be done once on your system, so including it in the markdown document results in needlessly executing it many times or writing flow control code to prevent that. If others will use the code, it is not polite to install a package on their system. Just run
install.packages("readxl")
in the console or use RStudio's menu Tools -> Install Packages.
I think the cause of the error is that the knitting of a document occurs in an environment that does not have access to all of the settings in your normal environment and the install.packages() function cannot find the on line repository. I may be wrong about that.
Francis