Importing CSV via API Stopped Working in R - r

I have some code that I have run multiple times successfully but today it randomly stopped working specifically its coercing a response from an API import into a data frame much like this:
results <- data.frame(httr::content(response))
Again this code worked before and other than some filtering of data I have not changed it.
The error I get is:
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
cannot coerce class ‘c("xml_document", "xml_node")’ to a data.
I trying to fix it and figure out what happened.
I am at a loss here. Let me know if you need more info.
Thanks.

Related

Create CYT object in CytoTree in 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.

DartR - Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric variables

I am very much a novice with R and am attempting to run a script that will filter a set of SNPs for 6 populations. I've successfully run this script before but I'm getting a new error in the initial stages of the script.
I've not been able to find anything similar to my issue online, though a few have the same error. The error comes up when R is trying to read in the SNP data and the function and error are as follows from the console screen:
>FijiHomaGL <- gl.read.dart(filename = "genCSV_modified.csv", ind.metafile = "COV_file.csv",
+ nas = "-", topskip = 6, lastmetric = TRUE, probar = TRUE)
Starting gl.read.dart
Starting utils.read.dart
Reading in the SNP data
Error in FUN(X[[i]], ...) :
only defined on a data frame with all numeric variables
A screenshot of the .csv file I'm trying to run
I'm not able to include the actual file but a screenshot is linked above for a general idea of the layout.
Any help is much appreciated I am very new so let me know if there is anything else I should include! Thanks in advance. The package being used for this function is dartR but I can't add it as a tag.

When using the function boxCox in R I keep getting this error "Error in as.data.frame.default(

I have the correct package alr4 which contains cars so it shouldn't be a problem with the function itself
box <- lm(Distance~Speed, data = stop)
boxCox(box)
This is the error
Error in as.data.frame.default(data, optional = TRUE) : cannot coerce class ‘"function"’ to a data.frame
The lm function runs just fine on its own, and I have used it in other analysis just fine, so it isn't an issue there. I am mostly just confused about the error and how to fix it. If you have suggestions or know why it happens that would be appreciated! Thanks

Error in 1:nrow(SM) : argument of length 0 for metadata file

Good day everyone
I am really struggling to get my metadata file in Rstudio for analysis. The import of the file is working perfectly fine, however, the moment I am trying to generate a phyloseq object this is the error I am getting: Error in 1:nrow(SM): argument of length 0.
My code:
# This is to import the file into Rstudio
metadata_ASV = read.table(file.choose(), header = TRUE, row.names = 1, sep = "\t")
I then check the form of the file
class(metadata_ASV)
The command below is the one I am using to generate the phyloseq object. This command did work previously but suddenly it is not working anymore.
ASV_sampledata = sample_data(metadata_ASV)
Any insight into what is causing the error:
Error in 1:nrow(SM): argument of length 0
Thank you in advance for any help on this.
Regards
Sunette

Problems parsing StreamR JSON data

I am attempting to use the streamR in R to download and analyze Twitter, under the pretense that this library can overcome the limitations from the twitteR package.
When downloading data everything seems to work fabulously, using the filterStream function (just to clarify, the function captures Twitter data, just running it will provide the json file -saved in the working directory- that needs to be used in further steps):
filterStream( file.name="tweets_test.json",
track="NFL", tweets=20, oauth=credential, timeout=10)
Capturing tweets...
Connection to Twitter stream was closed after 10 seconds with up to 21 tweets downloaded.
However, when moving on to parse the json file, I keep getting all sorts of errors:
readTweets("tweets_test.json", verbose = TRUE)
0 tweets have been parsed.
list()
Warning message:
In readLines(tweets) : incomplete final line found on 'tweets_test.json'
Or with this function from the same package:
tweet_df <- parseTweets(tweets='tweets_test.json')
Error in `$<-.data.frame`(`*tmp*`, "country_code", value = NA) :
replacement has 1 row, data has 0
In addition: Warning message:
In stream_in_int(path.expand(path)) : Parsing error on line 0
I have tried reading the json file with jsonlite and rjson with the same results.
Originally, it seemed that the error came from special characters ({, then \) within the json file that I tried to clean up following the suggestion from this post, however, not much came out of it.
I found out about the streamR package from this post, which shows the process as very straight forward and simple (which it is, except for the parsing part!).
If any of you have experience with this library and/or these parsing issues, I'd really appreciate your input. I have been searching non stop but haven't been able to locate a solution.
Thanks!

Resources