It seems very trivial but I can't read in jpeg, or any type of image into R 2.15. In R 2.10 I could do it using rimage library or ReadImage library - with read.jpeg for example - but there seems to be no way to do it in R 2.15 and later versions. Any thoughts on this?
library('ReadImages')
Error in library("ReadImages") : there is no package called ‘ReadImages’ >
install.packages('ReadImages') Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified)
Warning in install.packages : package ‘ReadImages’ is not available (for R version 2.15.1)
As pointed out in comments, try the jpeg package.
install.packages("jpeg") ## if necessary
library(jpeg)
## get help
library(help = jpeg)
## get more help
?readJPEG
Example, from the help:
# read a sample file (R logo)
img <- readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"))
Another option is rgdal, which can read from a massive bestiary of formats. Plotting and manipulation are handled differently.
install.packages("rgdal") ## if necessary
library(rgdal)
img <- readGDAL(file.path(R.home(), "doc", "html", "logo.jpg"))
There is also the readbitmap package on CRAN, it's always worth a basic search of the packages list for what you are looking for.
also:
## if not already installed
install.packages("jpeg")
library(jpeg)
?readJPEG()
img <- readJPEG("/Users/name/locationInFileDirectory/image.jpg", native = TRUE)
#this will display your image to test you read it correctly
if(exists("rasterImage")){
plot(1:2, type='n')
rasterImage(img,1,1,2,2)
}
Related
I'm trying to use copula on Rmd but am coming across a lot of issues with the formula:
Error: could not find function "pobs"
For example, I have already installed the packages before by typing this:
install.packages("VineCopula")
u <- pobs(as.matrix(cbind(cree,yahoo)))[,1]
v <- pobs(as.matrix(cbind(cree,yahoo)))[,2]
selectedCopula <- BiCopSelect(u,v,familyset=NA)
selectedCopula
Code based off this link: https://www.r-bloggers.com/modelling-dependence-with-copulas-in-r/
It seems you didn't load the VineCopula package before using it. install.packages is used to install packages, library is used to load them into your R session. This is what you should run:
library(VineCopula)
u <- pobs(as.matrix(cbind(cree,yahoo)))[,1]
v <- pobs(as.matrix(cbind(cree,yahoo)))[,2]
selectedCopula <- BiCopSelect(u,v,familyset=NA)
selectedCopula
You have installed the library in your code but haven't referenced it hence the functions are not available.
An example of this for reference would be installing an application on your phone; it gets installed but you need to open it in order to use it.
By using install.packages, the package was downloaded in your default home folder. You can change that using install.packages('package_name',lib.loc='path_on_your_system').
It is also a good practice to specify the library path before loading it.
.libPaths('path_on_your_system')
library(VineCopula)
u <- pobs(as.matrix(cbind(cree,yahoo)))[,1]
v <- pobs(as.matrix(cbind(cree,yahoo)))[,2]
selectedCopula <- BiCopSelect(u,v,familyset=NA)
selectedCopula
Let me know if this explanation helps.
I think I followed correctly from here. But why I got the error?
> library(magick)
Warning message:
package ‘magick’ was built under R version 3.2.5
> tiger <- image_read_svg('http://jeroen.github.io/images/tiger.svg', width = 400)
Error: could not find function "image_read_svg"
The version of magick is 0.4, how to install a newer version? I tried install.packages("magick") but it is still 0.4
> packageVersion("magick")
[1] ‘0.4’
I had an error with this function in magick version 2.2. Not same exact, but related enough that this may be useful:
Error in loadNamespace(name) : there is no package called ‘rsvg’
My error is due to R package rsvg not being installed automatically during my installation of magick. This may be your problem also. Installing it manually made function magick::image_read_svg work.
install.packages("rsvg")
library(rsvg)
library(magick)
tiger <- image_read_svg('http://jeroen.github.io/images/tiger.svg', width = 400)
print(tiger)
You should see a tiger image.
Maybe your version of magick does not have that function. We can check using apicheck (my own package, available on github).
library(apicheck)
when_fun_exists("magick::image_read_svg") # this will take some time...
But I am showing off. We could also just check the NEWS file on CRAN:
1.8
Export image_read_svg() and image_read_pdf()
Bet your version is before 1.8. You can check using packageVersion.
I've been working on a custom R library at work. I use functions from a couple different packages (always qualified with ::), so I've added them to the Imports section of my DESCRIPTION file. When I use R CMD INSTALL to install my package, I get a warning if the version of an imported package is too old, but installation continues. How do I force it to fail and alert the user that they need to update that package? I don't want to add any of them to the Depends section because I don't want those extra packages loaded when my library is loaded.
Example DESCRIPTION file:
Depends:
R (>= 3.1.2)
Imports:
dplyr (>= 0.7.0)
If dplyr 0.5.0 is loaded on the user's system, installation continues, but certain functions that depend on dplyr 0.7.0 will fail when called.
Here is a possible solution using find.package, packageDescription and packageVersion:
.onLoad <- function(libname, pkgname) {
myImports <- strsplit(utils::packageDescription(pkgname)[["Imports"]], split = ",\\s")[[1]]
if (length(find.package("dplyr", quiet = TRUE)) > 0) {
reqVers <- grep("^dplyr [(]", myImports, value = TRUE)
reqVers <- sub("^dplyr [(]>= ([0-9]+.*[0-9]+).*", "\\1", reqVers)
if (check <- utils::packageVersion("dplyr") < reqVers)
stop("Dplyr is version ", utils::packageVersion("dplyr"), " --- this package requires version ", reqVers, " at least")
}
invisible()
}
Like you say in the comment, common practice is to put this into a file called zzz.R.
Of course you could also replace the stop with a warning.
I am using readxl R package to read my .xlsx excel sheet, when I use range function, it shows me an error:
in read_excel("C:/Data/Digital/Actual.xlsx", range = "D11:E20", :
unused argument (range = "D11:E20")
My code is:
X <- read_excel("C:/Data/Digital/Actual.xlsx",range="D11:E20", col_names = FALSE, skip = 0)
Along with readxl, I have installed
library(cellranger)
library(Rcpp)
library(tibble)
library(tidyverse)
Also I am followin the guidelines stated in-
https://cran.r-project.org/web/packages/readxl/readxl.pdf
re-installing package <("readxl")> from "Tools" -> "Install Packages" -> "Repository" was installing old version.
I took zip file "readxl_1.0.0.zip" from the below location and installed it "Tools" -> "Install Packages" -> "Package Archive File". This resolves the issue.
version 1.0.0, readxl
New to R and have the following question. I got the error below when I was trying to create wordcloud in R. Could anyone tell me what the error means and is there a workaround?
Error in .overlap(x1, y1, sw1, sh1, boxes) :
function 'dataptr' not provided by package 'Rcpp'
That is an error we are getting with the newest Rcpp (which uses a different initialization scheme and no user-facing library). Make sure you have
the current version of Rcpp
and a current / rebuilt version of wordcloud.
On my system, with a fresh install of wordcloud, it all works fine:
R> library(wordcloud)
Loading required package: Rcpp
Loading required package: RColorBrewer
R> example(wordcloud)
wrdcldR> wordcloud(c(letters, LETTERS, 0:9), seq(1, 1000, len = 62))
wrdcldR> if(require(tm)){
wrdcld+
wrdcld+ ##### from character #####
wrdcld+ wordcloud(
wrdcld+ "Many years ago the great British explorer George Mallory, who
wrdcld+ was to die on Mount Everest, was asked why did he want to climb
wrdcld+ it. He said, \"Because it is there.\"
[.... more omitted ...]
After a while, I got it.
1) As stated, reinstall the latest version of Rcpp is the solution.
2) On top of that, if you use a library other than wordcloud that do not load automatically RCPP, do not forget to include
library(Rcpp)
or
require(Rcpp)
on your code before
dyn.load("your_shared_lib.so")
Source:
building_shared_libs_with_Rcpp