Create CYT object in CytoTree in R - r

I want to create a CytoTree CYT object in R to analyse my .FCS files. When I am using the Quick start code in the package description, I will always get an error when running the createCYT() function that says:
Error in createCYT(raw.data = fcs.data, normalization.method = "log") :
2022-09-26 15:46:26 meta.data must be a data.frame
As the function should not rely on any meta data and that object is optional, I do not know how to solve the error.
Here is the description:
https://ytdai.github.io/CytoTree/quick-start.html#quick-start-code
I thank you very much in advance for your help!
BR

I have encountered same problem previously.
In the end it worked only when the data.frame was added (yes, even though it should not depend on it).
Here is how:
meta.data <- data.frame(cell = rownames(fcs.data), stage = gsub(".fcs.+", "", rownames(fcs.data)))
meta.data$stage <- factor(as.character(meta.data$stage))
You may as well have a look at the Cytotree PDF in case of more issues.

Related

Error when running initPortf in Blotter package for R

I am having trouble initializing portfolios with the Blotter Package in R.
I am cycling through a list of variables that I want to initialize, and when I initialize with a single symbol, it works fine.
But when I try to do it with a list of symbols, it throws up the error:
Error in portfolio$symbols[[instrument]] <- new.env(hash = TRUE) :
wrong arguments for environment subassignment
Here is my code:
for (i in strategies) {
temp_symbol_list <- as.list(c(portfolio_txns %>%
filter(strategy == i) %>%
select(symbol)))
# temp_symbol_list <- as.list(temp_symbol_list)
print (i)
print (temp_symbol_list)
initPortf(i, temp_symbol_list,initDate = earliest_date, currency = "CAD")
}
When there is only one symbol in the intialize function, it works fine. But if there are two symbols, I get the error.
I have tried many different ways of creating the symbol list, but I think it is expecting something that I am not able to create.
For example, if I do the following:
initPortf("strategy",c("symbol 1","symbol 2"), initDate = earliest_date,
currency = "CAD")
it works fine.
Somehow, my list is the problem.
I figured it out.
I was created the variable to send to the initPortf as a "list". I changed it to a string and it worked.
Specifically, this is the new line
temp_symbol_list <- toString(temp_symbol_list)
I was confused as the documentation for the Blotter package said it was expecting a list, but I probably don't understand the different types of data storage properly.
I'm leaving this up in case someone else has the same problem.
Big thanks to the folks who wrote these packages btw.

truthTable in Rstudio Error: incorrect outcome specification

I was trying to do a QCA analysis of sufficeny in RStudio 4.1.3. using truthTable command. By running the code i get Error: wrong outcome specification. The outcome is written correctly. When I do an analysis of necessity with superSubset code everything works fine. Everything is coded numeric but it does not work with bivariate callibration either.
> ttCO21 <- truthTable( data = mydata, outcome = "CO21",
+ conditions = "GENDG1, FDI1, GDP1",
+ sort.by="incl, n", show.cases = TRUE, complete = TRUE)
**Error: Incorrect outcome specification.**
I had the same issue today and the solution was to delete any unnecessary columns (or create a new dataframe). I left only the calibrated conditions and outcome, because when I found this error, the raw data was in the same df, even if was not using it in the truthTable() command.
Because of the 3 hours i wasted on this problem i'll share my situation and solution. I had the exact same problem. creating a new df did not help, nor did removing unnecessary colums (wouldn't make sense anyway). Completely reinstalling en reloading the QCA package did work for me. Hope this helps someone.
you can try "comma" instead of "dot" (in “decimal") when you import file

#Error in table(StudentSurvey$Gender, StudentSurvey$Smoke): object 'StudentSurvey' not found

So, I'm attempting to knit a R document to a HTML file however, when it knits it produces this error "#Error in table(StudentSurvey$Gender, StudentSurvey$Smoke): object 'StudentSurvey' not found"
For reference this is my R code.
read.csv("StudentSurvey.csv")
barplot(table(StudentSurvey$Gender, StudentSurvey$Smoke), legend=TRUE)
boxplot(StudentSurvey$Pulse ~ StudentSurvey$Smoke , xlab = "Smoke" , ylab = "Pulse")
I'm unsure whats wrong, I've tried to troubleshoot by changing my Rworking directory and ensure that "StudentSurvey.csv" is in there, but alas this issue appears to be happening. If it isn't immediately apparent I'm extremely new to R as I'm using it for the first time in UNI so apologies if this is a simple fix.
you just need to assign the output of read.csv() to an object.
StudentSurvey <- read.csv("StudentSurvey.csv")

Importing a file only if it has been modified since last import and then save to a new object

I am trying to create a script that I run about once a week. The goal is that it will go out and check an MS Excel file that a co-worker manages. It then tests to see if the date the file was modified is newer then the last time it was imported. If it is newer, it will import the file (I am using readxl package - WONDERFUL!) into a new object that is a named with the date the original Excel file was last modified included in the object name. I have everything working except for the assignment of the imported data.frame to a new object that includes the date.
An example of the code I am using is:
First I create an object with a path pointing to the file of interest.
pfdFilePath <- file.path("H:", "3700", "3780", "002-00", "3.
Project Information", "Program", "RAH program.xls")
after testing to verify the file has been modified, I have tried simple assignment ("test" is just an example for simplification):
paste("df-", as.Date(file.info(pfdFilePath)$mtime), sep = "") <- "test"
But that code produces an error:
Error in paste("df-", as.Date(file.info(pfdFilePath)$mtime), sep = "") <- "test" :
target of assignment expands to non-language object
I then try the assign function:
assign(paste("df-", as.Date(file.info(pfdFilePath)$mtime), sep = ""), "test")
Running this code creates an object that looks to be okay, but when I evaluate it, or try using str() or class() I get the following error:
Error in df - df-2016-08-09 :
non-numeric argument to binary operator
I am pretty sure this is an error that has to do with the environment I am using assign, but being relatively new to R, I cannot figure it out. I understand that the assign function seems to be frowned upon, but those warnings seem to centered on for-loops vs. lapply functions. I am not really iterating within a function though. Just a dynamically named object whenever I run a script. I can't come up with a better way to do it. If there is another way to do this that doesn't require the assign function, or a better way to use assign function , I would love to know it.
Thank you in advance, and sorry if this is a duplicate. I have spent the entire evening digging and can't derive what I need.
Abdou provided the key.
assign(paste0("df.", "pfd.", strftime(file.info(pfdFilePath)$mtime, "%Y%m%d")), "test01")
I also converted to the cleaner paste0 function and got rid of the dashes to avoid confusion. Lesson learned.
Works perfectly.

R placing rugarch output into a dataframe

I have updated to the last version of R and updated the rugarch package as well.
Unfortunately some code that worked previously no longer works. I now get an error.
I would be greatful for some help to get the output into a dataframe.
library(rugarch)
data(sp500ret)
spec = ugarchspec( )
fit1 = ugarchfit(spec = spec, data = sp500ret)
df.fit1 <- as.data.frame(fit1,which="VaR")
Error in as.data.frame.default(fit1, which = "VaR"):
cannot coerce class "structure("uGARCHfit", package = "rugarch")" to a
data.frame
attributes(fit1)
shows:$fit$sigma
but when I try:
df1 <- data.frame(fit1$fit$sigma)
I get an error message;
Error in fit1$fit : $ operator not defined for this S4 class
as.data.frame(fit1, which="VaR") NEVER worked with an object of class uGARCHfit (you are confusing this with a uGARCHroll object). If you want the conditional VaR you can NOW (in the new version) use the quantile method e.g. quantile(fit1, c(0.01,0.05)).
If you want the conditional standard deviation then you should use sigma(fit1) which will return an xts matrix, or fit1#fit$sigma (# goes after an object in S4 classes). This and most other questions can be answered by carefully reading the documentation, vignette and the author's website which contains details of the changes.

Resources