I'm trying to load a library in an Rscript, but it's giving me a strange error. I'm running the 2.12.1 version of the Rscript binary, yet it complains that my package was built under version 2.12.1. Any idea what's going on here?
[17:55:13 trash] $ ./tmp.R
Loading required package: blah
Error: (converted from warning) package 'blah' was built under R version 2.12.1
[17:55:47 trash] $ cat tmp.R
#!/path/to/R/2.12.1/bin/Rscript --quiet
library(blah)
I figured it out with help from comments by #aL3xa and #Iterator. When I run whereis Rscript, I get:
Rscript: /usr/bin/Rscript /usr/bin/X11/Rscript
None of those represents the R installation I want to use (version 3.2.2 in this case), which would be located at
/myinstall/R-3.2.2/bin/
But if I run the Rscript command with the whole path, I force it to use the desired installation:
/myinstall/R-3.2.2/bin/Rscript tmp.R
which runs like a breeze.
Related
I am trying to install package SBCK from R build using Rscript build.R -c -v -i in windows command prompt following the steps given here. However, I ended up with package SBCK being not installed because of following error/warning InstallationWarning: package 'SBCK' is in use and will not be installed. I have no package with name SBCK installed on my system, so I do not understand why I am getting this warning message and thus not to be able to install the R package.
I know that similar question have been asked before here but solution there does not work in my case.
I am using R version 4.2.0 on Windows 10.
Once 'build.R' is run, "SBCK_0.5.0.tar.gz" is created in the 'SBCK-R' folder.
You can now install it via the package archive file option or pointing to that file in the install.packages command. I faced the same issue and this solved it.
I am working on Mac OSX, using v3.6.3 of R and using renv. In Rstudio and R, I can load the libraries of my installed packages, e.g library(ggplot2) works. However when I run a script using Rscript I get the message
Error in library(ggplot2) : there is no package called ‘ggplot2’
According to this SO answer, I need to make sure that the value of
Sys.getenv('R_LIBS_USER') in R.exe
is the same as the value of
Rscript.exe -e ".libPaths()"
But the value is the same, both are pointing to the renv-system-library in my project folder.
So how do I fix this?
It may be better to specify the lib.loc in library call
library(ggplot2, lib.loc = '/path/where/library/is/located')
I managed to solve this. akruns answer was useful, it did not work, but pointed me incorrect direction. The answer did not work because using it, I received the following error:
Error: package or namespace load failed for ‘ggplot2’:
.onLoad failed in loadNamespace() for 'pillar', details:
call: utils::packageVersion("vctrs")
error: there is no package called ‘vctrs’
Now vctrs was in the '/path/where/library/is/located' so I think dependent packages were not being loaded from that path but the default for Rscript. Putting a print(.libPaths() in the script gave
"/usr/local/Cellar/r/3.6.3_1/lib/R/library"
instead of
[1] "/Users/Chris/Sites/app_name/renv/library/R-3.6/x86_64-apple-darwin18.7.0"
[2] "/private/var/folders/5_/p_yl0439059b7_jdqzrm0hr40000gr/T/RtmptdHcWN/renv-system-library"
for .libPaths() in Rstudio. Looking at the ruby program that was actually running the Rscript program, I found it was being run with the --vanilla option, i.e
Rscript --vanilla script_name
Removing the --vanilla option fixed the problem. I think that scripts with the --vanilla option stopped working because I reinsalled R using brew to fix another problem I was having and as part of this issued this command:
brew link --overwrite r
When I go File-New File-R Notebook, it tells me to install some packages, but then it fails giving me this message:
Notebook Creation Failed:
"One of more packages required for R Notebook creation were not installed"
I'm trying to install those packages manually, but the package installation window disappears so quickly that I can't even see which ones I should install.
I googled it around, but couldn't fine any resource.
Can anyone help me with this?
Maybe at least provide a list of packages required to run R Notebook?
R notebooks are actually not created with a package named either RNotebook or notebook or anything similar but rather with the rmarkdown package, and it needs to be a current version. So the command would be:
install.packages("rmarkdown", dependencies=TRUE) # needs to be >= version 1.3
Then your pulldown menu selections should succeed in a current version of RStudio. .... at least that is if you have the system requirements listed in the CRAN webpage:
SystemRequirements: pandoc (>= 1.12.3) - http://pandoc.org
This worked for me:
Install latest version of R from cran website
Start RStudio pointing to this version of R.
On Mac set env variable as show below and start RStudio from terminal
Then "Install Package" in RStudio for "markdown" and other ppackages will work properly installing latest required packages to open notebook
➜ export RSTUDIO_WHICH_R=/usr/local/bin/R
Don't press the error message, and read whatever you can from the installation popup under it. In my case the last message was that it has problems compiling "digest". I installed "digest" manually (install.packages("digest",type = "binary")). Then it all worked.
Mac, R version 3.6, Rstudio desktop 1.2.
I had exactly the same problem. By reading the error logs, I found g++ command not found. So just installed it and it worked fine next time I've tried.
I faced the same problem. I am using the latest version of R and RStudio and all of the installed packages are up-to-date.
Now, talking about the error in installation of packages. Follow the steps below and you will have R Notebook up and running:
Run the command
install.packages("rmarkdown", dependencies=TRUE)
You will observe several messages on the console during installation. Browse through them and jot the ones where there is ERROR in installation of some other dependent package. In my case, it was 'backports'. The error message will be like this:
ERROR: compilation failed for package 'backports'
It can be different in your case but the point is to note down the name of the package that is facing compilation issues. Use an editor(npp) to save the name of the package.
Once you get the name of the package, execute the following command:
install.packages("backports", type="binary")
After successful execution of the above command, go to File drop down and select R Markdown. Go with auto installation of the rmarkdown and rprojroot packages. They will be successfully installed and you can now use R Notebook
Let us know if this solution worked for you.
I just found the answer myself so I'm posting.
I guess there was something wrong with the server.
I went into tools-global options-packages and chose different CRAN mirror, then it worked.
UPDATE YOUR VERSION OF R - that was my solution, I had the same problem.
( First two commands ensure you get the MOST RECENT version of R which I found on a Digital Ocean page)
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
$ sudo add-apt-repository 'deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu xenial/'
$ sudo apt-get update
$ sudo apt-get install r-base
WITHOUT the first two lines I ended up with R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
WITH the first two lines I got R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
After reinstalling R Studio, the Files -> RMarkdown was able to install all those subpackages and WORK. Hurray!
I am creating my own R package which depends on a function defined in R-package named fOption.
My NAMESPACE file has a line:
import(fOptions)
My DESCRIPTION file has a line:
Depends: fOptions
However, when I compile my R package using R CMD CHECL --as-cran option from the terminal, I get the following warning messages:
Found the following significant warnings:
Warning: package ‘timeDate’ was built under R version 3.1.2
Warning: package ‘timeSeries’ was built under R version 3.1.2
Warning: package ‘fBasics’ was built under R version 3.1.2
I found that these are dependencies of fOptions as its description file says:
Depends: methods, timeDate, timeSeries, fBasics
Does this mean that I cannot create my R package that depend on this particular R package (fOption)?
I am using OS X Version 10.9.4 and My R version is 3.1.1 (2014-07-10) -- "Sock it to Me".
Those are warnings, not errors, which means you can proceed but it's better if you address them.
In this case, you're getting the warnings because a few of the packages you need were built using an R version that is newer than the R version you are running. This can potentially be a problem, though it's likely not a problem, hence it's just a warning. If any of those packages have a different behaviour in the newer R version, for example, this would be critical, though that's likely not the case.
I would suggest updating your R version to 3.1.2, and that would get rid of these warnings plus you'll have a newer R version :) If you are working in an environment where you cannot update R, then it's fine, you can go on with your package with these warnings, it's just non-ideal.
My R was an environment within Anaconda - I was able to avoid this error by updating R as follows:
Open Anaconda Command line (this takes you to the base environment)
(base) C:\Users\grant>
Find the path to your R environment by running the following command:
(base) C:\Users\grant>conda envs
output:
# conda environments:
#
base * C:\Users\grant\Anaconda3
Python2p7 C:\Users\grant\Anaconda3\envs\Python2p7
R C:\Users\grant\Anaconda3\envs\R
rstudio C:\Users\grant\Anaconda3\envs\rstudio
Using the above path - activate your R environment:
(base) C:\Users\grant>activate C:\Users\grant\Anaconda3\envs\R
Now that your R environment is active - you can update your version of R as follows:
(R) C:\Users\grant>conda update r-caret
I am trying to load RQuantLib but I get the following error:
> require(RQuantLib)
Loading required package: RQuantLib
Error : .onLoad failed in loadNamespace() for 'RQuantLib', details:
call: if (is.character(qc) && nchar(qc) > 1) {
error: missing value where TRUE/FALSE needed
In addition: Warning message:
running command 'bash -c 'type -p quantlib-config' 2>/dev/null' had status 1
I am pretty new to programming in general so I am not sure what this means. I am working in an Mac OS Maverick environment, I downloaded the latest version of RQuantLib (0.3.12) and the "R Package Installer" says it is installed. (I installed RQuantLib from the terminal using "R CMD INSTALL RQuantLib" as using install.packages() from within R did not work - it gave me an error saying QuantLib was not configured, although it was running fine in from the terminal.) I am running R from the R console. QuantLib works fine and so does Rcpp.
I checked the "NAMESPACE" document in the RQuantLib folder and it says:
import(methods)
importFrom(Rcpp, Rcpp.plugin.maker)
useDynLib(RQuantLib)
exportPattern("*.default")
export(
##--arrays.R
"oldEuropeanOptionArrays",
"EuropeanOptionArrays",
"plotOptionSurface",
##--asian.R
"AsianOption",
##--bermudan.R
"BermudanSwaption",
"summary.G2Analytic",
"summary.HWAnalytic",
"summary.HWTree",
"summary.BKTree",
##--bond.R
"ZeroCouponBond",
"ZeroPriceByYield",
"ZeroYield",
"FixedRateBond",
"FixedRateBondYield",
"FixedRateBondPriceByYield",
"FloatingRateBond",
"ConvertibleZeroCouponBond",
"ConvertibleFixedCouponBond",
"ConvertibleFloatingCouponBond",
"CallableBond",
"FittedBondCurve",
##--calendars.R
"isBusinessDay", "businessDay",
"isHoliday",
"isWeekend",
"isEndOfMonth",
"getEndOfMonth", "endOfMonth",
"adjust",
"advance",
"businessDaysBetween",
"getHolidayList", "holidayList",
"setCalendarContext",
##--dayCounter.R
"dayCount",
"yearFraction",
"setEvaluationDate",
##--discount.R
"DiscountCurve",
"plot.DiscountCurve",
##--implied.R
"EuropeanOptionImpliedVolatility",
"AmericanOptionImpliedVolatility",
"BinaryOptionImpliedVolatility",
##--option.R
"EuropeanOption",
"AmericanOption",
"AmericanOption.default",
"BinaryOption",
"BarrierOption"
)
S3method("plot", "Option")
S3method("print", "Option")
S3method("summary", "Option")
S3method("plot", "Bond")
S3method("print", "Bond")
S3method("summary", "Bond")
If I try to specify the path where the Terminal wrote that it installed RQuantLib while requiring it I get the following error:
> require('RQuantLib', lib.loc = "C:/Users/dealmer/Library/R/3.1/library/RQuantLib/libs")
Loading required package: RQuantLib
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
no library trees found in 'lib.loc'
So, do I need to move something from there to where the other R libraries are? (There is already a folder named "RQuantLib" in the folder where the other R library folders are, that's where I found the NAMESPACE doc for example) The path that the Terminal gave me I can't follow in the Finder window however because it doesn't show the "Library" folder and I don't know how to make it do that.)
This is what .libPaths() gives me:
> .libPaths()
[1] "/Users/dealmer/Library/R/3.1/library"
[2] "/Library/Frameworks/R.framework/Versions/3.1/Resources/library"
The R libraries are in [2].
I've tried googling but I can't find anything that seems helpful. Any help will be very appreciated. Thank you
- Dom
I think the issue is that on Linux we have quantlib-config in the $PATH:
edd#max:~$ quantlib-config --help
Usage: quantlib-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] \
[--libs] [--cflags]
edd#max:~$ quantlib-config --version
1.4
edd#max:~$
I don't own an OS X box, so I depend on someone like you help with a better configure setup. It should just work if you copy (or soft-link) quantlib-config into your path (eg /usr/local/bin), or adjust $PATH otherwise to include the directory it is in.
I had the same issue and after some hours of struggle I manage to use something not very rigorous but it works!
It seems that R has some issues evaluating system("bash -c 'type -p quantlib-config'").
After having installed QuantLib, typing the command bash -c 'type -p quantlib-config' in Terminal gives us the path of our quantlib-config which is for me /opt/local/bin/quantlib-config.
So I went back to my source folder for RQuantLib (version 0.4.0) and replaced qc in file R/inline.Rby:
qc <- as.character("/opt/local/bin/quantlib-config")
and rebuilt the package using the terminal command R CMD install RQuantLib/.
As I said, not very sexy but it works.
A restart of R and Rstudio is necessary.
Hope it helps!