xml file conversion in R
0
0
Entering edit mode
3.3 years ago
Kira • 0

Hello everyone ^.^ I just learn R recently and met a problem. I have downloaded the data from TCGA and wanted to convert the xml file inside the unzip file. These are the code that I used:


1)

rm(list = ls())    
options(stringsAsFactors = F)

2)

setwd("C:/Users/User/Desktop/Bioinformatics")

3)

project <- "TCGA-LUAD"
clinicaldir <- "./Samples/Clinicaldata"

4)

library(XML)
library(methods)

5)

xmlFileNames <- dir(path=clinicaldir, full.names = T, pattern = "xml$", recursive = T)

6)

PatientClinicalList <- lapply(xmlFileNames, 
                              function(x){#x=xmlFileNames[1]
                                result <- xmlParse(file=x)
                                rootnode <- xmlRoot(result)
                                xmldataframe <- xmlToDataFrame(rootnode[2])
                                return(t(xmldataframe))})

7)

ClinicalDataList <- t(do.call(cbind, PatientClinicalList))

I got stuck at step 7, it shows

Error in (function (..., deparse.level = 1)  : 
      number of rows of matrices must match (see arg 2)

and I have no idea how to solve it.

Can anyone please help me solve it?

Thank you very much

R • 859 views
ADD COMMENT
0
Entering edit mode

Go through it step by step. Examine each member of PatientClinicalList and see where the cbind fails.

ADD REPLY
0
Entering edit mode

Extremely grateful for your reply. I've tried traceback() and debug(), still I could not locate the exact location which cause this error, erm... maybe I got the wrong code. Is there any code suggest?

ADD REPLY
0
Entering edit mode

Try t(do.call(cbind, PatientClinicalList[1:10])) etc until you can figure out where it breaks. This is a more basic/grounded approach to debugging that miight help nail the exact element.

ADD REPLY
0
Entering edit mode

Thank you very much for your help

ADD REPLY

Login before adding your answer.

Traffic: 1752 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6