Question: xml file conversion in R
0
gravatar for Kira
6 weeks ago by
Kira0
Kira0 wrote:

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 • 130 views
ADD COMMENTlink modified 27 days ago by Biostar ♦♦ 20 • written 6 weeks ago by Kira0

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

ADD REPLYlink written 6 weeks ago by Ram32k

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 REPLYlink written 6 weeks ago by Kira0

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 REPLYlink written 6 weeks ago by Ram32k

Thank you very much for your help

ADD REPLYlink written 6 weeks ago by Kira0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1265 users visited in the last hour
_