Recommenderlab error unable to find inherited method - r

I'm a newbie in R and need some advice with recommenderlab.
I have a "training" dataset comprised of 6 variables, and the first line looks like this:
song_id user_id title release artist_name year
3 SOAAAGQ12A8C1420C8 384e068d83822096b2ef9a35ba520d97a8f74741 Orgelblut Dolores Bohren & Der Club Of Gore 2008
I'm trying to use recommenderlab to use UBCF, and use the following code:
rec <- Recommender("train", method = "UBCF")
But get this error
Error in (function (classes, fdef, mtable) : unable to find an
inherited method for function ‘Recommender’ for signature
‘"character"’
Any idea what is wrong?

train should be your training data, not a string. Can you try this:
rec <- Recommender(train, method = "UBCF")

Related

R "unable to find an inherited method for function" type error in migrateR, when making mvmt objects from ltraj objects

I have been following the migrateR vignette while traying to create animal movement models.
So far I made a list of ltraj objects from the adehabitat package and have worked with that:
set.coordinates <- function(x){coordinates(x) <- c("Long","Lat"); x}
set.proj4string <- function(x){proj4string(x) <- CRS("+proj=longlat +datum=WGS84"); x}
Base_ind <- lapply(Base_ind, set.coordinates)
Base_ind <- lapply(Base_ind, set.proj4string)
make.ltraj <- function(q){as.ltraj(xy=coordinates(q), date=q$TelemDate, id=q$AID,
burst = q$AID, infolocs = q[4])}
Base_ind_tr <- lapply(Base_ind, make.ltraj)
make.nsd <- function(x){mvmtClass(x)}
Base.nsd <- lapply(Base_ind_tr, make.nsd)
After this the error appears:
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘burst’ for signature ‘"ltraj", "missing"’
My ltraj objects look the same as in the vignette:
Type of the traject: Type II (time recorded)
Time zone: UTC *
Irregular traject. Variable time lag between two locs
Characteristics of the bursts:
id burst nb.reloc NAs date.begin date.end
1 An1 An1 1323 0 2021-05-26 11:02:26 2021-10-24 17:00:38
infolocs provided. The following variables are available:
[1] "elev"
burst exists as an attribute of the ltraj objects.
I have also gotten the error for individual animals and for all of them in a single data frame.
I have a vague idea how these sort of errors occur but am not sure how to solve it.

export data frame to till format

I am using night-time light satellite data. I have performed a calibration method between two satellite data for the same year. for which I had converted the tiff file to dataframe. Now I need to export the data frame to tiff format. following are the codes I tried but some error is shown
library (sp)
library (raster)
library (rgdal)
writeRaster(NTL_new2, "E:\phd\data\calliberation test\rstudio\test.tif", format="GTiff", overwrite=TRUE)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘writeRaster’ for signature ‘"data.frame", "character"’
can anyone guide me on how to go about
That is the type of message you will get when attempting to apply an S4 generic function to an object of a class for which no defined S4 method exists (or at least has been attached to the current R session).
Here's an example using the raster package (for spatial raster data), which is chock full of S4 functions.
library(raster)
## raster::rotate() is an S4 function with just one method, for "Raster" class objects
isS4(rotate)
# [1] TRUE
showMethods(rotate)
# Function: rotate (package raster)
# x="Raster"
## Lets see what happens when we pass it an object that's *not* of class "Raster"
x <- 1:10
class(x)
# [1] "integer"
rotate(x)
# Error in (function (classes, fdef, mtable) :
# unable to find an inherited method for function ‘rotate’ for signature ‘"integer"’

Problem extracting specific transcript sequences from genome

I'm working on Linux in R to get specific transcript sequences from the genome. I am able to import the genome, extract transcripts annotations (tx), and get transcript sequences (tx_seq). I am also able to import genomic annotations for the transcripts I'm interested in as GRanges (uorf_annotations) and convert them transcript coordinates (uorf_tx_annotations).
The libraries I have loaded are
#BiocManager::install(version="3.9")
#BiocManager::install("BSgenome.Hsapiens.UCSC.hg19")
#BiocManager::install("S4Vectors")
#BiocManager::install(c("GenomicFeatures", "Biostrings", "GenomicRanges"))
library(broom)
library(BSgenome.Hsapiens.UCSC.hg19)
library(Biostrings)
library(GenomicRanges)
library(GenomicFeatures)
library(rtracklayer)
library(tidyverse)
library(plyranges)
options(scipen=999)
The chunk of code that works is
uorf_tx_annotations <- mapToTranscripts(uorf_annotations, tx) %>%
print()
I get stuck when I try and get the transcript sequences from uorf_tx_annotations. The code I am using for this step is
uorf_transcript_seq <- extractTranscriptSeqs(genome, uorf_tx_annotations) %>%
print()
and the error I am getting is "Error in extractTranscriptSeqs(genome, uorf_tx_annotations) : failed to extract the exon ranges from 'transcripts' with exonsBy(transcripts, by="tx", ...)"
I use extractTranscriptSeqs earlier on to get tx_seq, so I'm not sure what's wrong here. I thought that everything I needed was in GRanges, but in case uorf_annotations wasn't in the GRanges I tried (inspired from documentation at https://rdrr.io/bioc/GenomicFeatures/man/extractTranscriptSeqs.html)
uorf_tx_annotations <- mapToTranscripts(uorf_annotations, tx) %>%
exonsBy(by = "tx") %>%
print()
but this just introduces a new error: "Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘exonsBy’ for signature ‘"GRanges"’"

Dynamic variable names in for loops combined with gdal

I have the following problem trying to somehow solve:
I created 10 arrays of different IDW interpolations using the gstat/gdal package.
Now I have the following variables, which I´m trying to export to my harddrive:
DI.IDW.SAND.P.0.1, DI.IDW.SAND.P.0.2, [...]
In all it´s 10 different arrays for the different powers (ipd values) used during the interpolation.
Manual export to the hard drive works just fine:
writeGDAL(DI.IDW.Sand.P.0.1, fname = vec.rast[1], drivername = "GTiff", mvFlag = -1)
But now automation is where I can´t figure out the correct solution:
I created a data.frame containing the relevant information for the for loop:
runner.sand = data.frame("IDP" = c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1), "str"=c("DI.IDW.Sand.P.0.1", "DI.IDW.Sand.P.0.2", "DI.IDW.Sand.P.0.3", "DI.IDW.Sand.P.0.4", "DI.IDW.Sand.P.0.5", "DI.IDW.Sand.P.0.6", "DI.IDW.Sand.P.0.7", "DI.IDW.Sand.P.0.8", "DI.IDW.Sand.P.0.9", "DI.IDW.Sand.P.1"))
Then I tried:
for (i in c(1:length(runner.sand[,1]))) {
writeGDAL(paste("DI.IDW.Sand.P", runner.sand[i,1], sep = "."), runner.sand[i,2], drivername = "GTiff")
}
But I always get this error:
Error in nchar(fname) : 'nchar()' requires a character vector
Also when trying to automate proj4string I get this error:
for (i in c(1:length(runner.sand[,2]))) {
proj4string(runner.sand[i,2]) = CRS(paste("+init=epsg:",epsg,sep=""))
#dat.ov = over(IDP.opt, runner.sand[i,2]) # for later idp optimazation with residual values
#IDP.opt = cbind(IDP.opt#data, dat.ov)
}
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function 'proj4string' for signature '"character"'
Again, it perfectly works if I put in the "normal" variable name manually:
proj4string(DI.IDW.Sand.P.0.1) = CRS(paste("+init=epsg:",epsg,sep=""))
I also tried solutions shown here with assign, but nothing does the job.
Thanks for your help!

Can't Inspect Text Corpus in R

I am trying to create Corpus for further analysis, the code I am showing You suddenly stopped working and I cannot find solution for this error. I execute this:
library("tm")
library("SnowballC")
library("wordcloud")
library("arules")
library("arulesViz")
#library("e1071")
#WCZYTAJ_DANE######################################################################
setwd("D:/Dysk Google/Shared/SGGW/MGR_R2/Metody Eksploracji Danych/_PROJEKT")
smSPAM <- read.table("smSPAM.txt", sep="\t", quote="", stringsAsFactors = F)
dim(smSPAM)
colnames(smSPAM) <- c("class", 'text')
head(smSPAM,50)
#zamienia spam ham na 1 0
smSPAM$class=ifelse(smSPAM$class=="ham", "0", "1")
head(smSPAM$text,50)
#View(smSPAM[smSPAM$class=="1",])
#STWORZ_KORPUS#####################################################################
#tworze korpus na potrzeby documenttermmatrix
smSPAM.corp <- Corpus(VectorSource(smSPAM$text))
inspect(smSPAM.corp)
But I get this error in log:
Error in (function (classes, fdef, mtable):
unable to find an inherited method for function ‘inspect’ for signature ‘"VCorpus"’
However I can still perform stemming, removing white spaces etc. on this Corpus, only inspect doesn't work.
Ok I found what my problem was - both tm and arules packages containt inspect functions do I had to detach arulesViz and arules (in that order cause latter is needed by former) and It's working again.

Resources