How to solve unused argument error as part of a meltAssay? - r

When using meltAssay to convert a SummarizedExperiment object, the central data infrastructure for microbiome analysis in Bioconductor, into long data.frame, I use the following lines according to the instructions in the book:
tse <- transformSamples(tse, method="relabundance")
molten_tse <- meltAssay(tse,
add_row_data = TRUE,
add_col_data = TRUE,
assay_name = "relabundance")
molten_tse
However, I get the following error:
Error in .melt_assay(x, abund_values, feature_name, sample_name, ...)
: unused argument (assay_name = "relabundance")

Use the following syntax instead: (abund_values instead of assay_names.
There seems to be an error in the book)
molten_tse <- meltAssay(tse,
add_row_data = TRUE,
add_col_data = TRUE,
abund_values = "relabundance")

Related

Error in w2v_train(trainFile = file_train, modelFile = model, stopWordsFile = file_stopwords (full error text below)

Full error text: Error in w2v_train(trainFile = file_train, modelFile = model, stopWordsFile = file_stopwords, : Expecting a single string value: [type=closure; extent=1].
I am trying to run a word embedding analysis using this data https://www.kaggle.com/datasets/therohk/million-headlines?resource=download to obtain:
top 25 closest words to focus word
plot these 25 words
compare same analysis with different data (JSTOR data on articles with "populism" https://constellate.org/dataset/f53e497b-844e-2b60-ec2f-b9c54d2e334e?unigrams=political,%20social)
I loaded all the data and necessary packages, as well as pre-processing the ABCNews data for the analysis. (See code)
#Loading necessary packages
install.packages(c("tidyverse", "tidytext", "word2vec", "Rtsne", "future", "jstor", "magritrr", "ggplot2", "dplyr"))
library("tidyverse")
library("tidytext")
library("word2vec")
library("Rtsne")
library("future")
library("jstor")
library(magrittr)
library("ggplot2")
library("dplyr")
#Preprocessing abcnews data
##Select text data from csv file ABC NEWS FILE
head(abcnews_pop)
abc_pop_text <- abcnews_pop %>%
select("headline_text")
head(abc_pop_text)
I then used the following code to process the embedding:
#ABCNews data
text_news<-abc_pop_text%>%
txt_clean_word2vec(.,ascii = TRUE, alpha = TRUE, tolower = TRUE, trim = TRUE)
set.seed(123456789)
news_model<-word2vec(x=text, type = "cbow", dim = 500, iter = 50)
embedding_news<-as.matrix(news_model)
The first function (text_news<-abc_pop...) ran smoothly. However, the second one (set.seed(123456789) news_model...) puts out this mistake:
Error in w2v_train(trainFile = file_train, modelFile = model, stopWordsFile = file_stopwords, : Expecting a single string value: [type=closure; extent=1].
Does anyone know how to address this?
I had an error in naming objects/variables. This has been resolved, thank you.

Redefine arguments within an R core package function

My fingers are starting to tire of typing update.packages(checkBuilt = T, ask = F). I was wondering whether it's possible to redefine the default parameters within the update.packages() function. So far, I've tried adding the following to my .Rprofile file:
utils::assignInNamespace(
"update.packages",
function(checkBuilt = TRUE, ask = FALSE, ...) {
update.packages(checkBuilt = checkBuilt, ask = ask, ...)
},
"utils"
)
But when I try to use the function in R I get the following error:
update.packages()
Error: C stack usage 7976404 is too close to the limit
I've also just tried using formals() with the following in the .Rprofile:
local({
args_new <- alist(lib.loc = .libPaths(), ask = FALSE, checkBuilt = TRUE)
ind <- which(methods::formalArgs(update.packages) %in% names(args_new))
formals(update.packages)[ind] <- args_new
})
But that results in the following error upon launching R:
Error in formals(update.packages) : object 'update.packages' not found
As #Roland said in the comments, your definition is recursive. You shouldn't bother with the assignInNamespace: keeping the new function in your workspace is good enough. Then you can use utils::update.packages in its definition, e.g.
update.packages <- function(checkBuilt = TRUE, ask = FALSE, ...)
utils::update.packages(checkBuilt = checkBuilt, ask = ask, ...)
You should avoid using assignInNamespace for the reasons listed in its help page.

arulesViz subscript out of bounds paracoord

I want to perform basket analysis and draw a paracoord plot however I receive an error.
Content of this error is: :
Error in m[j, i] : subscript out of bounds.In addition: Warning message:
In cbind(pl, pr) :
number of rows of result is not a multiple of vector length (arg 2)
I am using data from: Link.
First I am transforming this to fit basket analysis, name of the original excel files is Online_Retail:
library(arules)
library(arulesViz)
library(plyr)
items <- ddply(Online_Retail, c("CustomerID", "InvoiceDate"), function(df1)paste(df1$Description, collapse = ","))
items1 <- items["V1"]
write.csv(items1, "groceries1.csv", quote=FALSE, row.names = FALSE, col.names = FALSE)
trans1 <- read.transactions("groceries1.csv", format = "basket", sep=",",skip=1)
And to draw paracoord I have created such a code:
rules.trans2<-apriori(data=trans1, parameter=list(supp=0.001,conf = 0.05),
appearance=list(default="rhs", lhs="ROSES REGENCY TEACUP AND SAUCER"), control=list(verbose=F))
sorted.plot <- sort(rules.trans2, by="support", decreasing = TRUE)
plot(sorted.plot, method="paracoord", control=list(reorder=TRUE, verbose = TRUE))
Why my code for paracoord is not working? how can I fix it? What should I change?
This is, unfortunately, a bug in arulesViz. This will be fixed in the next release (arulesViz 1.3-3). The fix is already available in the development version on GitHub: https://github.com/mhahsler/arulesViz

Eventstudies package r phys2eventtime null

I am using the eventstudies package in R and I am struggling to replicate the eventsudy function which is used as an example in the package as below:
# Event study without adjustment
es <- eventstudy(firm.returns = StockPriceReturns,
event.list = SplitDates,
event.window = 7,
type = "None",
to.remap = TRUE,
remap = "cumsum",
inference = TRUE,
inference.strategy = "bootstrap")
I use my own data for StockPriceReturns and SplitDates and even though I have tried to make them of the same format, type etc of those above I think this is where it is failing. The message I am getting is:
Error in phys2eventtime(z = returns$firm.returns, events =
event.list[i, : events$name should a character class. In addition:
Warning message: In is.na(events$name) : is.na() applied to
non-(list or vector) of type 'NULL'
Any help would be much appreciated.

How to customize clustering in mclust?

I am trying to use the mclust package of R. I want to cluster some data.
Here are the steps to what I have done :
Reading data :
mydata <- read.table("\Users......", row.names= 1, sep = "\t", header = TRUE)
Using mclust : library(mclust)
mydataModel <- Mclust(mydata)
summary(mydataModel)
It breaks into 7 clusters. However, I want my data to be broken only into 2 clusters. Please help on how to do ?
As mentioned by MrFlick, you should read the documentation by adding a ?function().
In your case, do ?Mclust() in your R console to see how default parameters have been set up.
This will show up once you do ?Mclust()
Mclust(data, G = NULL, modelNames = NULL,
prior = NULL,
control = emControl(),
initialization = NULL,
warn = mclust.options("warn"), ...)
All you need to do is:
Mclust(mydata, 2)

Resources