Rscript does not load methods package, R does -- why, and what are the consequences?
?Rscript the methods package isn't loaded because, "The default for Rscript omits methods as it takes about 60% of the startup time."
Why Rscript doesn't work with function as()?
as function belongs to the
methods package. Rscript doesn't load the
methods package to save startup time (see the help of Rscript
help(Rscript) ). You would have to tell Rscript to load the package.
Rscript could not find function
Rscript doesn't load the methods package by default, because it's time-consuming. So you either need to specify it on the command line:
Rscript --default-packages=methods file.R
library(methods) at the top of the file you're calling.
R package not loading `Imports` packages
Summarizing to close, there were a few issues here:
packagename::fun()is a good choice, but doesn't work well for operators. Especially with the pipe (
%>%), using e.g. a function instead, would defeat it's purpose.
@importFromtags are preferable to
@import, as this is more narrow and explicit. Both of these affect the NAMESPACE file upon calling
roxygen2::roxygenize(). Note however, that roxygen does not mess with user-defined NAMESPACE files, as it is often the case that people would rather take care of it manually themselves (e.g. when a package provides S3 classes and/or methods), and an overwrite by roxygen would then need to be undone. Deleting an existing NAMESPACE file would let roxygen re-create it. Roxygen typically adds a line to the NAMESPACE file to recognize whether it should update it or not:
# Generated by roxygen2: do not edit by hand
The dependencies in the DESCRIPTION file are neither modified by roxygen, nor does roxygen add them to the NAMESPACE (note that this would else result in full package imports, which we would rather avoid through
@importFrom). The DESCRIPTION file needs to be taken care of manually, making sure that the Imports: section covers all the packages used via the NAMESPACE, i.e. through
@importFrom, as well as via
Add Max Value to a New Column in R
Generate Dynamic R Markdown Blocks
How to Multiply Data Frame by Vector
Calculating Mean for Every N Values from a Vector
Fill Missing Combinations in a Dataframe
Rmarkdown: How to Change the Font Color
Faster Weighted Sampling Without Replacement
Add (Subtract) Months Without Exceeding the Last Day of the New Month
How to Add a Table to My Ggplot2 Output
How to Scrape Tables Inside a Comment Tag in HTML with R
Colorbar from Custom Colorramppalette
Rstudio Not Picking the Encoding I'm Telling It to Use When Reading a File
Getting a Stacked Area Plot in R
Wide to Long Multiple Measures Each Time
Why Does Merge Result in More Rows Than Original Data
Handling Dates When We Switch to Daylight Savings Time and Back