Error in asMethod(object) : is an unknown item label error - r

I am doing association analysis using R.
This is the code I am using to generate rules:
rules <- apriori(trans, parameter = list(supp = .07,conf = 0.50,smax=6,minlen=3,maxlen=9,target = "rules"))
This code is giving me the set of rules for the given dataset, however if I try to find rules for particular consequent then I am getting an error.
Here is the code:
rules2 <- apriori(data=trans,parameter=list(supp = .07,conf = 0.5,smax=6,minlen=3,maxlen=9,target = "rules"),
appearance = list(default="lhs",rhs="CMDB"),
control = list(verbose=F))
and this is the error I am getting :
"Error in asMethod(object) : CMDB is an unknown item label"
How do I generate the correct rule?
Thanks.

You should write like this
appearance=list(rhs=c("CMDB"))

Related

dbutils.fs.mount() works for Python but not for R?

The following code works in a Azure Databricks Python cell:
dbutils.fs.mount(
source = "wasbs://my-container#mystorageaccount.blob.core.windows.net",
mount_point = "/mnt/mount1",
extra_configs = {"fs.azure.account.key.mystorageaccount.blob.core.windows.net":dbutils.secrets.get(scope = "my-scope", key = "storagekey")})
However, if I try to run this code from an Azure Databricks R cell I get an error, can somebody explain what's going on?
dbutils.fs.mount(
source = 'wasbs://my-container#mystorageaccount.blob.core.windows.net',
mountPoint = '/mnt/mount1',
extraConfigs = {'fs.azure.account.key.mystorageaccount.blob.core.windows.net':dbutils.secrets.get(scope = 'my-scope', key = 'storagekey')}
)
Warning in as.list(extraConfigs) : NAs introduced by coercion Warning in as.list(extraConfigs) : NAs introduced by coercion Error in
"fs.azure.account.key.mystorageaccount.blob.core.windows.net":dbutils.secrets.get(scope
= "my-scope", : NA/NaN argument Some( Error in
"fs.azure.account.key.mystorageaccount.blob.core.windows.net":dbutils.secrets.get(scope
= "my-scope", : NA/NaN argument ) Error in "fs.azure.account.key.mystorageaccount.blob.core.windows.net":dbutils.secrets.get(scope
= "my-scope", : NA/NaN argument
The problem is that you're trying to use Python syntax for extraConfigs parameter, but it's incorrect. In R you need to use following syntax for dicts: c(key1="value1", key2="value2")

R:Error in UseMethod(generic = "as.sparse", object = x)

enter image description here
I'm trying to use "Seurat" to analyze B cells for my tutor, but the following error occurs when I try to create the object and I don't know how to correct it.
pbmc <- CreateSeuratObject( counts = BC.data$'B Cells`, Project = " BC.data",min.cells = 3, min.features = 200)
Error in UseMethod(generic = "as.sparse", object = x) :
no applicable method for 'as.sparse' applied to an object of class "Seurat"

Error in lines.etm(x[[i]], tr.choice = tr.choice[j], col = col[j + (i - : Argument 'tr.choice' and possible transitions must match

When trying to plot cif data in R :
plot(cif.kweet) this error pops up:
"Error in lines.etm(x[[i]], tr.choice = tr.choice[j], col = col[j + (i - :
Argument 'tr.choice' and possible transitions must match", what does this mean, how to solve it?
Additional information:
cif.kweet <-etmCIF(Surv(entry, exit, cause !=0) ~ group, data, etype=data$cause, failcode=3)

Reducing equations using R

I've got this small snippet for reducing a large system:
# set up the multipliers
g1 = (s+9)/((s)*(s+6)*(s+12)*(s+14))
g2 = ((6)*(s+9)*(s+17))/((s+12)*(s+32)*(s+68))
h1 = 13
h2 = 1/(s+7)
# reduce the system in parts
s1 = (g2)/(1 + (g2)*(h1))
s2 = (s1)*(g1)
s3 = (s2)/(1 + (s2)*(h2))
# now we have a unity feedback
g = s3
show(g)
g should be the reduced equation from doing the operations above. However, I get a bunch of errors when I run the code:
Error : object 's' not found
Error : object 's' not found
Error : object 's' not found
Error : object 'g2' not found
Error : object 's1' not found
Error : object 's2' not found
Error : object 's3' not found
Error : error in evaluating the argument 'object' in selecting a method for function 'show': Error: object 'g' not found
Am I not using equations correctly?
edit: my intentions are to have s as a free variable
In order to evaluate your first line of code, there must be an object s that is already defined.
It sounds like your goal is to create a function that outputs g from a single input s. The below code wraps your calculations in a function called make_g:
make_g <- function(s){
# set up the multipliers
g1 = (s+9)/((s)*(s+6)*(s+12)*(s+14))
g2 = ((6)*(s+9)*(s+17))/((s+12)*(s+32)*(s+68))
h1 = 13
h2 = 1/(s+7)
# reduce the system in parts
s1 = (g2)/(1 + (g2)*(h1))
s2 = (s1)*(g1)
s3 = (s2)/(1 + (s2)*(h2))
# now we have a unity feedback
g = s3
g
}
Now, you can call the functions using whatever value for s you like:
make_g(s = 1)

overriding R's incomplete error messages

When a call exists of multiple lines, a potential error only includes the first line of match.call() resulting in some lost information and an incomplete sentence. A simple example:
#proper error message:
runif(n=1, k=5)
#incomplete error message:
runif(n=1, k={5})
What would be a way to get R to include the full call to the error message (maybe by collapsing the multiple lines or so)? I am mostly interested in using this in a tryCatch setting.
I had a go at investigating the error object in a tryCatch setting via:
tryCatch( runif(n=1,k={5}),
error = function(e) recover() )
And then selected the 4th environment (value[[3]](cond)) to examine e.
I noticed that e$call was:
Browse[1]> e$call
runif(n = 1, k = {
5
})
So it seems that the error message just uses that first line.
You can collapse all the lines together with:
Browse[1]> paste(deparse(e$call),collapse='')
[1] "runif(n = 1, k = { 5})"
So you could try something like:
tryCatch( runif(n=1,k={5}),
error = function(e) {
cat(sprintf('Error in %s: %s\n',
paste(deparse(e$call),collapse=''),
e$message))
} )
But this doesn't fix up the error message itself, just the call leading up to it:
Error in runif(n = 1, k = { 5}): unused argument(s) (k = {
So the 'Error in xxx' is complete, but the 'unused argument(s) xxx' is still not. It's a start, but not all the way there.
I'm not sure how to improve on this (and am also interested to know if it's possible).

Resources