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

2.4k Views Asked by At

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
1

There are 1 best solutions below

1
On

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 (e.g. 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)