R warning: " 'package:stats' may not be available when loading" - r

I've been working with the arules package and RODBC package for a few days now in RStudio. I saved the workspace image multiple times in the meantime. But today I wanted to save my workspace image again and now I get this warning:
Warning message:
In save(list = ls(envir = .GlobalEnv, all.names = TRUE), file = outfile, :
'package:stats' may not be available when loading
I only used arules and RODBC functions and str_split_fixed from stringr and some standard stuff like data.frame.
I didn't even use the stats package at all. When reloading the workspace image, it doesn't seem affected by it. But the warning is bothering me anyway, especially since stats is supposed to be a standard package of R, how can it be unavailable... How can I resolve this warning?

As the commentator didn't post his comment as an answer, I will close this question myself: it's a bug in RStudio and knowing this thanks to SO I could close down RStudio and a couple R programming sessions later the warning message did not occur again.

This is now an official rstudio bug.
In my case (the repro in the bug) the root cause was that one of the objects I was trying to save referenced an rstudio-internal function (this isn’t very exotic. A plain options call returns a list that does that). RStudio functions live in tools:rstudio namespace, which inherits the stats package among others - hence the warning.
It is currently planned to be fixed as part of v1.4.

Related

Does anyone know what this error message (from the 'readxl' package in R) means?

I'm trying to open an Excel worksheet in R using the 'readxl' package function 'read_excel'.
library(readxl)
Test <- read_excel("Test.xlsx",sheet = "Sheet1")
I've used the exact same bit of code on the exact same excel workbook many times over the past year, and it has never caused a problem. This time, though, I get:
Error: object ‘data_frame’ is not exported by 'namespace:vctrs'
I've tried calling the file different things, moving it to different locations, opening different files etc. but am now always getting this error with the read_excel function. I can usually work out what to do in response to an error message by searching for the relevant string in Google. However, I've tried searching for this error message, and haven't found anything that looks helpful yet. If anyone has any ideas, these would be much appreciated!
It looks like data_frame is relatively new to vctrs. You may need to update your vctrs package. You may have accidentally rolled back to an earlier version?
Seems it was added here:
vctrs 0.3.3 2020-08-27

How to get rid of a size warning in R for package development

I am working on submitting an R package and when I run
devtools::check()
I get the following warning:
W checking sizes of PDF files under ‘inst/doc’ (1.6s)
‘gs+qpdf’ made some significant size reductions:
compacted ‘Vignette1.pdf’ from 544Kb to 256Kb
compacted ‘Vignette2.pdf’ from 328Kb to 69Kb
consider running tools::compactPDF(gs_quality = "ebook") on these files
I understand that the size of the PDFs are the issue, and that they need to be resized, but can anyone explain to me where I need to place tools::compactPDF(gs_quality = "ebook") in my code so that when the vignettes are created this is not an issue. You cannot submit an R package that throws a warning so I need to come up with a solution to fix this.
If you do R CMD build --help you will see the two lines
--compact-vignettes= try to compact PDF files under inst/doc:
"no" (default), "qpdf", "gs", "gs+qpdf", "both"
Per recent discussion on the mailing lists, you may want arguments gs+qpdf or both. You may want to experiment with both. Use of the option should render a package that does not trigger the NOTE.
And I presume there is a way to pass that onto devtools as well but I am not familiar with its functions so I can't give you a direct pointer.
As of devtools 2.4.5
devtools::check(build_args = "--compact-vignettes=gs+qpdf")
is the correct parameterization. But note that for building, the corresponding call is now
devtools::build(args = "--compact-vignettes=gs+qpdf")
Note that in neither case do you quote the argument passed down to R CMD BUILD's --compact-vignettes

R Package Build/Install Error: "object not found" even though I have it in R/sysdata.rda

Similar Question
accessing sysdata.rda within package functions
Why This Similar Question Does Not Apply To Me
They were able to actually build it, and apparently it was a Github error for them (not related)
R VERSION
3.4.2 (I tried using 3.4.3 as well but the same problem occurred)
EDIT: I am on Windows 10
Context
I have fully read the following tutorial on R packages and how to include .Rda files in them. I have LazyData in my DESCRIPTION file set as true as well. I have tried both the data/ folder implementation and the R/sysdata.rda implementation using the function devtools::use_data() with the respective options of internal = FALSE and internal = TRUE.
However, when I try to build the package, or use devtools::install (which builds as well I assume), it fails and gives me the following error message:
Error in predict(finalModel, newInput) : object 'finalModel' not found
Where finalModel is stored within my .rda file.
Does anyone know any possible reasons why this might occur?
I also asked a coworker to install the package on his machine, but unfortunately he got the exact same error.
I made another test package as a 'sanity-check' by creating a simple linear model using the lm() function on datasets::swiss, and then made a test package with this newly created model as a .rda file. When I referenced this test model in a function within this test package, it eerily worked, despite the fact that (to the best of my knowledge) I used the exact same steps to create this new R package.
Also, I unfortunately cannot share the code for the package I am creating, but I am willing to share the code for the test package that uses the swiss dataset.
Thank you in advance.
EDIT: My .rda file I am putting in the package was created last year, if that has anything to do with it.
I just solved a similar issue of having object 'objectName' not found that arose during package management. In my case, the issue related to losing the context of variables when working with parallelization.
When using parallel::clusterExport(cl, varlist=c("function-name")), clusterExport looks at .GlobalEnv for variable definitions. This wouldn't come up during debugging, as I always the variables defined in .GlobalEnv. The solution was to state the environment explicitly: parallel::clusterExport(cl, varlist=c("function-name"), envir=environment()). This ensures that the parallel processes have context of the variables within the data/ folder and R/sysdata.rda.
Source
If you have more than one internal file, you must save them together:
usethis::use_data(file_1,
file_2,
file_3,
internal = TRUE,
overwrite = TRUE)

R devel: Warning: multiple methods tables found for ‘append’

I am maintaining an R package that recently started throwing the following warning during R CMD check packagename:
** testing if installed package can be loaded
Warning: multiple methods tables found for ‘append’
(The package is called phyloseq, and the branch that is currently causing me this problem is here)
Refined subquestions:
So the "multiple methods tables" part, this seems to imply that I have two dependent packages with a collision over dispatch for the append method. Right?
I don't have a function/method named "append" in this package, and don't import any.
I was able to reproduce the warning message in a new R session by simply loading two of the packages in R at the same time, one of which (RJSONIO) is a second-level dependency -- by which I mean one of my dependencies (biom) depends on it, but not mine:
library("RJSONIO");library("Biostrings")
Which throws the warning in the R session:
multiple methods tables found for ‘append’
And naturally, append is exported in the NAMESPACE file of both RJSONIO and Biostrings. What I don't understand is why this should cause a problem when loading my package. The packages I directly depend on (Biostrings-2.28.0, biom-0.3.8) are not fully imported -- certainly not importing any append methods. How else could this conflict arise?
Workaround:
If I update Biostrings to the "devel" version, 2.29.2, then the warning appears to go away. Most users will not do this, however, and I'd still like to understand how this collision is even possible, given the way I specifically imported functions and classes from these packages rather than full Import or Depends.

The cause of "bad magic number" error when loading a workspace and how to avoid it?

I tried to load my R workspace and received this error:
Error: bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘WORKSPACE_Wedding_Weekend_September’ has magic number '#gets'
Use of save versions prior to 2 is deprecated
I'm not particularly interested in the technical details, but mostly in how I caused it and how I can prevent it in the future. Here's some notes on the situation:
I'm running R 2.15.1 on a MacBook Pro running Windows XP on a bootcamp partition.
There is something obviously wrong this workspace file, since it weighs in at only ~80kb while all my others are usually >10,000
Over the weekend I was running an external modeling program in R and storing its output to different objects. I ran several iterations of the model over the course of several days, eg output_Saturday <- call_model()
There is nothing special to the model output, its just a list with slots for betas, VC-matrices, model specification, etc.
I got that error when I accidentally used load() instead of source() or readRDS().
Also worth noting the following from a document by the R Core Team summarizing changes in versions of R after v3.5.0 (here):
R has new serialization format (version 3) which supports custom serialization of
ALTREP framework objects... Serialized data in format 3 cannot be read by versions of R prior to version 3.5.0.
I encountered this issue when I saved a workspace in v3.6.0, and then shared the file with a colleague that was using v3.4.2. I was able to resolve the issue by adding "version=2" to my save function.
Assuming your file is named "myfile.ext"
If the file you're trying to load is not an R-script, for which you would use
source("myfile.ext")
you might try the readRDSfunction and assign it to a variable-name:
my.data <- readRDS("myfile.ext")
The magic number comes from UNIX-type systems where the first few bytes of a file held a marker indicating the file type.
This error indicates you are trying to load a non-valid file type into R. For some reason, R no longer recognizes this file as an R workspace file.
Install the readr package, then use library(readr).
It also occurs when you try to load() an rds object instead of using
object <- readRDS("object.rds")
I got the error when saved with saveRDS() rather than save(). E.g. save(iris, file="data/iris.RData")
This fixed the issue for me. I found this info here
Also note that with save() / load() the object is loaded in with the same name it is initially saved with (i.e you can't rename it until it's already loaded into the R environment under the name it had when you initially saved it).
I had this problem when I saved the Rdata file in an older version of R and then I tried to open in a new one. I solved by updating my R version to the newest.
If you are working with devtools try to save the files with:
devtools::use_data(x, internal = TRUE)
Then, delete all files saved previously.
From doc:
internal If FALSE, saves each object in individual .rda files in the data directory. These are available whenever the package is loaded. If
TRUE, stores all objects in a single R/sysdata.rda file. These objects
are only available within the package.
This error occured when I updated my R and R Studio versions and loaded files I created under my prior version. So I reinstalled my prior R version and everything worked as it should.

Resources