Why "image_read_svg" could not work in R? - r

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.

Related

How to use function "get_data_structure"

I try to use the function "get_data_structure" but got an error as below.
Could anyone know how to fix it?
Thank you in advance
get_data_structure("DUR_D")
Error in data.frame(data_structure#concepts) :
trying to get slot "concepts" from an object (class "data.frame") that is not an S4 object
The problem appears to be a bug in the version of the OECD package on CRAN. If you install the development version, it works. First, close R and reopen a clean new session, then run this:
remotes::install_github("https://github.com/expersso/OECD")
library(OECD)
get_datasets()
get_data_structure("DUR_D")
remotes::install_github("https://github.com/expersso/OECD")
library(OECD)
dataset <- "DUR_D"
dstruc <- get_data_structure(dataset)
Try with get_dataset("DUR_D") i.e. without -s. as get_datasets() with -s will return a dataframe of available datasets.
It is a bug in the package OECD 0.2.5.
It works with the package version 0.2.4 which you can install from CRAN's archived package section (https://cran.r-project.org/src/contrib/Archive/OECD).
If you want to access the archived package version directly in R, use the following code:
devtools::install_version("OECD", version = "0.2.4", repos = "https://stat.ethz.ch/CRAN/")
Note that this requires the package 'devtools' to be installed.

edgarWebR started giving error related to xml2 package

This worked in mid-February, but stopped as of yesterday. It looks like there might have been some updates to xml2 subsequently, not sure if this is a factor.
library(edgarWebR)
filing_list <-
edgarWebR::company_filings(
as.character("AAPL"),
ownership = FALSE,
type = "10-K",
before = "2020207",
count = 40,
page = 1)
Error in xml2::url_absolute(res[[ref]], xml2::xml_url(doc)): Base URL must be length 1
Using xml2 1.3.0 and edgarWebR 1.0.1, but also tried previous versions of both.
Raised an issue with edgarWebR, but any pointers would be greatly appreciated.
I had the same exact problem and your post actually helped me fix it.
1: Go into 'packages' on RStudio and delete all versions of the xml2 package.
2: Restart R
3: Run these lines of code:
require(devtools)
install_version("xml2", version = "1.2.2", repos = "http://cran.us.r-project.org")
More info here https://support.rstudio.com/hc/en-us/articles/219949047-Installing-older-versions-of-packages
Author of edgarWebR here - I did a bit of debugging, here is the issue in xml2 I opened that, once fixed, should allow using a current version - https://github.com/r-lib/xml2/issues/300

Creating wordcloud and I got this 'dataptr' not provided by package 'Rcpp'

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

how to read.jpeg in R 2.15

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)
}

dependent packages not loading in R on Debian

I'm having trouble loading the sde package on a clean Debian install running R 2.11.1. I've seen this behavior with some other packages, however, so I don't think it's specific to only this one package. Here's an example of the conundrum:
>install.packages("sde", lib.loc=libPath)
... installs sde, and the packages it's dependent on: zoo, fda
> library(sde, lib=libPath)
Loading required package: fda
Error: package 'fda' could not be loaded
In addition: Warning message:
In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) :
there is no package called 'fda'
ok, that's odd. I saw fda being installed. So I manually load the dependencies:
> library(zoo, lib=libPath)
> library(fda, lib=libPath)
Loading required package: splines
ok, that worked. Now let's try sde:
> library(sde, lib=libPath)
To check the errata corrige of the book, type vignette("sde.errata")
WTF? it loaded fine?!?
So why can I manually load the packages but R is not picking them up automagically?
Adding to my confusion, I discovered during debugging that if I don't use the lib=libPath then everything works just fine. So it looks like the use of a custom path for packages is screwing this all up... but why?
You confirmed my suspicions in the comments. You need to do one of two things:
.libPaths(libPath)
or
library(sde, lib=c(libPath,.libPaths()))
I prefer the first method because the second requires you do that for all calls to library.

Resources