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

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

Related

Importing CSV via API Stopped Working in 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.

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.

Difficulty opening a package data file of unknown type

I am trying to load the state map from the maps package into an R object. I am hoping it is a SpatialPolygonsDataFrame or something I can turn into one after I have inspected it. However I am failing at the first step – getting it into an R object. I do not know the file type.
I first tried to assign the map() output to an R object directly:
st_m <- maps::map(database = "state")
draws the map, but str(st_m) appears to do nothing, unless it is redrawing the same map.
Then I tried loading it as a dataset: st_m <- data("stateMapEnv", package="maps") but this just returns a string:
> str(stateMapEnv)
chr "R_MAP_DATA_DIR"
I opened the maps directory win-library/3.4/maps/mapdata/ and found what I think is the map file, “state.L”.
I tried reading it with scan and got an error message I do not understand:
scan(file = "D:/Documents/R/win-library/3.4/maps/mapdata/state.L")
Error in scan(file = "D:/Documents/R/win-library/3.4/maps/mapdata/state.L") :
scan() expected 'a real', got '#'
I then opened the file with Notepad++. It appears to be a binary or compressed file.
So I thought it might be an R data file with an unusual extension. But my attempt to load it returned a “bad magic number” error:
st_m <- load("D:/Documents/R/win-library/3.4/maps/mapdata/state.L")
Error in load("D:/Documents/R/win-library/3.4/maps/mapdata/state.L") :
bad restore file magic number (file may be corrupted) -- no data loaded
Observing that these responses have progressed from the unhelpful through the incomprehensible to the occult, I thought it best to seek assistance from the wizards of stackoverflow.
This should be able to export the 'state' or any other maps dataset for you:
library(ggplot2)
state_dataset <- map_data("state")

Unable to read an SBML file in SBMLR

I'm trying to read a SBML file (Test.xml) using the R package SBMLR. Below is the code I executed.
library(SBMLR)
file <- system.file("models","Test.xml",package = "SBMLR")
doc <- readSBML(file)
When I execute the 3rd line I get an error message saying:
Error in xmlEventParse(filename, handlers = sbmlHandler(),
ignoreBlanks = TRUE) : File does not exist
I have tried to read the file using rsbml library as well.. But still I'm getting an error saying
Error: File unreadable.
I'm following this guide at the moment. Any help regarding the issue is highly appreciated!

Error in ls(envir = envir, all.names = private)?

The below error keeps coming up inconsistently when I try to read excel files into R using the 'XLConnect' package.
Error in ls(envir = envir, all.names = private) :
invalid 'envir' argument
I have actually run into this error while even using other packages that read excel files like package 'xlsx' and 'xlsReadWrite'. Many times restarting the R session solves this problem, which leads me to think that something else I am doing in my R session is changing the environment and not allowing me to load excel files anymore. Below is the latest example of code that is causing this error. In this case I know that the following coding sequence is causing the error to appear - but why is that happening? And how can I get past this error if I need the chron package.
library("XLConnect")
wb2 <- loadWorkbook("excel_file", create = FALSE)
library(chron)
wb2 <- loadWorkbook("excel_file", create = FALSE)
Anyone else run into this issue before? Any help on this issue is greatly appreciated!
Before reopening the workbook try removing the reference to previously opened one, so:
rm(wb2)
wb2 <- loadWorkbook("excel_file", create = FALSE)
Also, make sure that "excel_file" is not open by excel or any other program while you run the R test.
I've seen the same error come up when using XLConnect and the above seemed to help.
Had this problem a couple of times and the call stack looks like this message is generated when a "OutOfMemory" Exception is thrown.
To solve this problem I used:
options( java.parameters = "-Xmx4g" )
to increase the heap size rJava is able to use.
Debugging with options(error=utils::recover) helped a lot, because the R error messages are not very specific.

Resources