Conceptual Stucture doesn't accept clust - r

I use the latest version of package and I try to run this:
I try to run this example:
library(bibliometrix)
download.file("https://www.bibliometrix.org/datasets/joi.zip", destfile = temp<-tempfile())
M <- convert2df(readLines(unz(temp, "joi.txt")), dbsource="isi",format="plaintext")
CS <- conceptualStructure(M, method="MCA", field="ID", minDegree=10, clust=5, stemming=FALSE, labelsize=8,documents=20)
but I receive this error:
Error in conceptualStructure(M, method = "MCA", field = "ID", minDegree = 10, :
unused argument (clust = 5)
What should change?

Related

Writing to database in parallel in R

I try to write a table which is a processed subset of a global data variable, in a normal for loop this piece of code works fine but when I try to do it in parallel it raises an error.
Here is my piece of code;
library(doParallel)
library(foreach)
library(odbc)
library(data.table)
nc <- detectCores() - 1
cs <- makeCluster(nc)
registerDoParallel(cs)
con <- dbConnect(odbc(),driver = 'SQL Server',server = 'localserver',database = 'mydb', encoding = 'utf-8',timeout = 20)
range_to <- 1e6
set.seed(1)
random_df <- data.table(a = rnorm(n = range_to,mean = 2,sd = 1),
b = runif(n = range_to,min = 1,max = 300))
foreach(i=1:1000,.packages = c('odbc','data.table')) %dopar% {
subk <- random_df[i,]
subk <- subk**2
odbc::dbWriteTable(conn = con,name = 'parallel_test',value = subk,row.names = FALSE,append = TRUE)
}
This code raises this error;
Error in {: task 1 failed - "unable to find an inherited method for function 'dbWriteTable' for signature '"Microsoft SQL Server", "character", "data.table"'"
Like I said before in a normal for loop it works fine.
Thanks in advance.
I solved that issue by changing only creating connection object method by;
parallel::clusterEvalQ(cs, {library(odbc);con <- dbConnect(odbc(),driver = 'SQL Server',server = 'localserver',database = 'mydb', encoding = 'utf-8',timeout = 20)})

Get data from Workspace in Azure ML Studio

I have a problem with connecting to workspace in Azure ML Studio. I am using library azuremlsdk, but it doesn't work.
My code looks like:
library(azuremlsdk)
workspace_name = 'workspace_name'
subscription_id = 'subscription_id'
resource_group = 'resource_group'
ws <- get_workspace(name = workspace_name, subscription_id = subscription_id, resource_group = resource_group)
dataSet <- get_dataset_by_name(ws, name = "registration_name", version = "latest")
After I run that code I get error:
I have know idea what is wrong. I tried to do it in python and it works fine with the same parameters, code:
from azureml.core import Workspace, Dataset
subscription_id = 'subscription_id'
resource_group = 'resource_group'
workspace_name = 'workspace_name'
workspace = Workspace(subscription_id, resource_group, workspace_name)
dataset = Dataset.get_by_name(workspace, name='registration_name')
Any idea how can I fix that bug?
I tried to reproduce the issue and got the solution. Follow the below procedure to access the dataset contents from the workspace.
data.set <-data.frame(installed.packages("azuremlsdk"));
data.set <-data.frame(installed.packages("remotes"));
remotes::install_cran('azuremlsdk', repos = 'http://cran.us.r-project.org', INSTALL_opts=c("--no-multiarch"))
library(azuremlsdk)
ws <- get_workspace(name = workspace_name, subscription_id = subscription_id, resource_group = resource_group, auth = authentication)
print(ws)
dataSet <- get_dataset_by_name(ws, name = "registration_name", version = "latest")
dataSet

Trouble with running h2o.hit_ratio_table

I got this issue when I run H2o for xgboost. May I ask how can I solve this issue? Thank you.
I run this code
h2o.hit_ratio_table(gbm2,valid =T)
And I encounter this error
" Error in names(v) <- v_names :
'names' attribute [1] must be the same length as the vector [0]"
Then I proceed run
mean(finalRF_prediction$predict==test_gb$Cover_Type)
and I got the error:
Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = page, :
ERROR MESSAGE:
Name lookup of 'NULL' failed
My model is:
gbm2=h2o.gbm(training_frame = train_gb,validation_frame = valid_gb,x=1:51,y=52,
model_id="gbm2_covType_v2",
ntrees=200,
max_depth = 30,
sample_rate = .7,
col_sample_rate = .7,
learn_rate=.3,
stopping_round=2,
stopping_tolerance = .01,
score_each_iteration = T,seed=2000000)
finalRF_prediction=h2o.predict(object=gbm2,newdata = test_gb)
summary(gbm2)
h2o.hit_ratio_table(gbm2,valid=T)[1,2]
mean(finalRF_prediction$predict==test_gb$Cover_Type)
Without having a dataset to rerun your code on it's hard to say what caused the error. For your second error, check if the column Cover_Type exists in your test_gb dataframe.
The code you have seems to be fine, so I would just double check your column names.
In addition here is a code snippet with xgboost that shows you, you can use the hit_ratio_table() successfully.
library(h2o)
h2o.init()
iris.hex <- h2o.importFile( "http://h2o-public-test-data.s3.amazonaws.com/smalldata/iris/iris_wheader.csv")
i.sid <- h2o.runif(iris.hex)
iris.train <- h2o.assign(iris.hex[i.sid > .2, ], "iris.train")
iris.test <- h2o.assign(iris.hex[i.sid <= .2, ], "iris.test")
iris.xgboost.valid <- h2o.xgboost(x = 1:4, y = 5, training_frame = iris.train, validation_frame = iris.test)
# Hit ratio
hrt.valid.T <- h2o.hit_ratio_table(iris.xgboost.valid,valid = TRUE)
print(hrt.valid.T)

R CMD check not recognizing S3 generic methods

I'm writing a package and if I run the code in my Rstudio it runs but when I give it to R CMD check to run, it doesn't recognize the S3 methods.
I have a generic method:
count_kmers <- function(obj, klen = 6, parallel = TRUE,
nproc = ifelse(parallel, comm.size(), 1),
distributed = FALSE) {
UseMethod("count_kmers", obj)
}
And then the substitute methods:
count_kmers.character <- function(obj, klen = 6, parallel = TRUE,
nproc = ifelse(parallel, comm.size(), 1),
distributed = FALSE) {...}
count_kmers.AAStringSet <- function(obj, klen = 6, parallel = TRUE,
nproc = ifelse(parallel, comm.size(), 1),
distributed = FALSE){...}
Now an example that I run in my documentation is:
seqs <- AAStringSet(c("seq1"="MLVVD",
"seq2"="PVVRA",
"seq3"="LVVR"))
## Count the kmers and generate a dataframe of the frequencies
freqs <- count_kmers(seqs, klen = 3, parallel = FALSE)
head(freqs)
If I run the code as a normal code it works but if I check it using R CMD check then it will complain:
Error in UseMethod("count_kmers", obj) :
no applicable method for 'count_kmers' applied to an object of class "c('AAStringSet', 'XStringSet', 'XRawList', 'XVectorList', 'List', 'Vector', 'list_OR_List', 'Annotated')"
The AAStringSet is an object from the Biostrings package. But that doesn't matter, even if I pass a character string to count_kmers, I'm receiving the same error but saying:
no applicable method for 'count_kmers' applied to an object of class "character".

Unused arguments in R error

I am new to R , I am trying to run example which is given in "rebmix-help pdf". It use galaxy dataset and here is the code
library(rebmix)
devAskNewPage(ask = TRUE)
data("galaxy")
write.table(galaxy, file = "galaxy.txt", sep = "\t",eol = "\n", row.names = FALSE, col.names = FALSE)
REBMIX <- array(list(NULL), c(3, 3, 3))
Table <- NULL
Preprocessing <- c("histogram", "Parzen window", "k-nearest neighbour")
InformationCriterion <- c("AIC", "BIC", "CLC")
pdf <- c("normal", "lognormal", "Weibull")
K <- list(7:20, 7:20, 2:10)
for (i in 1:3) {
for (j in 1:3) {
for (k in 1:3) {
REBMIX[[i, j, k]] <- REBMIX(Dataset = "galaxy.txt",
Preprocessing = Preprocessing[k], D = 0.0025,
cmax = 12, InformationCriterion = InformationCriterion[j],
pdf = pdf[i], K = K[[k]])
if (is.null(Table))
Table <- REBMIX[[i, j, k]]$summary
else Table <- merge(Table, REBMIX[[i, j,k]]$summary, all = TRUE, sort = FALSE)
}
}
}
It is giving me error ERROR:
unused argument (InformationCriterion = InformationCriterion[j])
Plz help
I'm running R 3.0.2 (Windows) and the library rebmix defines a function REBMIX where InformationCriterion is not listed as a named argument, but Criterion.
Brief invoke REBMIX as :
REBMIX[[i, j, k]] <- REBMIX(Dataset = "galaxy.txt",
Preprocessing = Preprocessing[k], D = 0.0025,
cmax = 12, Criterion = InformationCriterion[j],
pdf = pdf[i], K = K[[k]])
It looks as though there have been substantial changes to the rebmix package since the example mentioned in the OP was created. Among the most noticable changes is the use of S4 classes.
There's also an updated demo in the rebmix package using the galaxy data (see demo("rebmix.galaxy"))
To get the above example to produce results (Note: I am not familiar with this package or the rebmix algorithm!!!):
Change the argument to Criterion as mentioned by #Giupo
Use the S4 slot access operator # instead of $
Don't name the results object REDMIX because that's already the function name
library(rebmix)
data("galaxy")
## Don't re-name the REBMIX object!
myREBMIX <- array(list(NULL), c(3, 3, 3))
Table <- NULL
Preprocessing <- c("histogram", "Parzen window", "k-nearest neighbour")
InformationCriterion <- c("AIC", "BIC", "CLC")
pdf <- c("normal", "lognormal", "Weibull")
K <- list(7:20, 7:20, 2:10)
for (i in 1:3) {
for (j in 1:3) {
for (k in 1:3) {
myREBMIX[[i, j, k]] <- REBMIX(Dataset = list(galaxy),
Preprocessing = Preprocessing[k], D = 0.0025,
cmax = 12, Criterion = InformationCriterion[j],
pdf = pdf[i], K = K[[k]])
if (is.null(Table)) {
Table <- myREBMIX[[i, j, k]]#summary
} else {
Table <- merge(Table, myREBMIX[[i, j,k]]#summary, all = TRUE, sort = FALSE)
}
}
}
}
I guess this is late. But I encountered a similar problem just a few minutes ago. And I realized the real scenario that you may face when you got this kind of error msg... It's just the version conflict.
You may use a different version of the R package from the tutorial, thus the argument names could be different between what you are running and what the real code use.
So please check the version first before you try to manually edit the file. Also, it happens that your old version package is still in the path and it overrides the new one. This was exactly what I had... since I manually installed the old and new version separately...

Resources