24

I am building R package in R version 3.1.3, but whenever i try to install it I get the following error message;

* installing *source* package ‘SPO’ ...
** R
** data
*** moving datasets to lazyload DB
** preparing package for lazy loading
Error : argument "data" is missing, with no default
Error : unable to load R code in package ‘SPO’
ERROR: lazy loading failed for package ‘SPO’
* removing ‘/home/evans/Desktop/SPO.Rcheck/SPO’

Kindly any help on how to fix lazy loading problem will be highly appreciated. Thank you.

nico
  • 50,859
  • 17
  • 87
  • 112
Evans Otieno
  • 279
  • 1
  • 4
  • 5
  • 4
    Are you running a function that has a missing argument `"data"` somewhere in the package? Try running all examples, functions, demos, etc. individually in the console of a fresh R session. – Rich Scriven Aug 20 '15 at 16:00
  • Thank you so much. I fixed the problem, it was about missing argument in one of my functions. – Evans Otieno Aug 20 '15 at 19:24
  • 3
    "ERROR: lazy loading failed for package" is just R stating that it encountered an error when trying to build the package; the underlying problems are the errors listed on the previous lines. – Martin Smith Jul 31 '17 at 11:55

5 Answers5

13

This error message also occurs if you have uncommented code in the function file that is outside of the function definition.

The solution is to comment out, or delete, the code that is not inside your function.

hackR
  • 1,459
  • 17
  • 26
  • Definitively the right thing to do for me. But a simple precision : the error occurs when you have written something outside the functions you've written in R (any file in the R directory is concerned), not the C++ files... – Boubacar Traoré Jul 23 '20 at 18:38
3

In my case, I found an inactive/unused R file in the R folder of the package I wanted to build.

Once I deleted/removed this file, I was able to build the package.

madsR
  • 95
  • 6
2

The error is usually caused by missing arguments (as stated in the comments) or packages.

For example, I had the following in my package:

library("DESeq2")

I couldn't build and install my package because the package DESeq2 was not installed. Once I installed the package, everything worked.

ABCD
  • 7,914
  • 9
  • 54
  • 90
  • I'm pretty sure that you are not supposed to use `library()` in a package. See http://r-pkgs.had.co.nz/r.html#r-differences – Paul de Barros Apr 21 '17 at 16:35
1

Inspired by madsR suggestion I have deleted .RData and .Rhistory files from the package folder. Then the error kindly disappeared.

Bogdan
  • 864
  • 10
  • 18
  • 1
    Personally, I had a .txt file in the data subdirectory which was not documented. I erased the file and everything went back to normal. – Denis Cousineau Mar 12 '21 at 23:02
0

I had the same error for installing package gt. The problem was that my magrittr should have been updated before loading gt. But trying to updating that also didn't work and adding True for dependencies and closing and re-opening of RStudio also not helped me. So, I tried to clear my environment in RStudio because there seemed to be an error related to that, and then everything worked fine.

rez
  • 290
  • 2
  • 12