简体   繁体   中英

R - knitr - ShareLatex - install.packages(xyz)

How do I install packages in a ShareLatex knitr file (.Rtex)?? The R code

par(mfrow=c(1,1))
install.packages("tree")
library(tree)
model.tree.simpel <- tree(response~.,data=dat)
plot(model.tree.simpel)
text(model.tree.simpel)

Error message

Installing package into '/usr/local/lib/R/site-library'## (as 'lib' is unspecified)##
Warning in install.packages("tree"):
'lib = "/usr/local/lib/R/site-library"' is notwritable##
Error in install.packages("tree"):  unable to install packages##
Error in library(tree):  there is no package called 'tree'##
Error in eval(expr, envir, enclos):  could not find function "tree"##
Error in plot(model.tree.simpel):  object 'model.tree.simpel' not found##
Error in text(model.tree.simpel):  object 'model.tree.simpel' not found

It seems like you cannot install packages but you can upload them. I use here the DPI package as an example. It seems like the official sharelatex server runs on a linux x86_64 machine. So your packages need to be compiled on such a machine (eg ubunut 64)

  1. Find the DPI package on you local x86_64-pc system (eg. ~/R/x86_64-pc-linux-gnu-library/3.1/DPI )
  2. create a DPI folder in sharelatex
  3. upload the content of your local DPI folder in the sharelatex DPI folder
  4. user the DPI package with library(DBI)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM