Reading website table comes with a list name “NULL” in R












0















I want to read a table directly from a webpage with R. In reader's view the webpage with the table looks like this:



enter image description here



I used two packages to read the table from the webpage. It worked OK except the fact that the table is read as a list.



library(RCurl)
library(XML)
d<-getURL('https://securewordpresswebsiteAddress/data/')
d<-readHTMLTable(d, header=T)


Here is what I get after reading the table



> d
$`NULL`
ID X Y Depth P
1 1046 256857 2632323 13 2.8
2 1054 257090 2632039 13 1.1
3 1057 257099 2631981 13 2.6
4 1058 257071 2632004 9 2.1
5 1060 257173 2632004 13 4
6 1089 257194 2631660 13 14.1


Where is this $NULL coming from? is there a way to avoid it?










share|improve this question

























  • websiteAddress does not seem to resolve in my browser. it wouldn't be a site that prohibits scraping, would it?

    – hrbrmstr
    Nov 24 '18 at 2:38











  • no i gave a fictitious link, the webpage is not prohibiting scraping

    – ToNoY
    Nov 24 '18 at 2:42











  • Someone else will likely take your word for it.

    – hrbrmstr
    Nov 24 '18 at 2:55
















0















I want to read a table directly from a webpage with R. In reader's view the webpage with the table looks like this:



enter image description here



I used two packages to read the table from the webpage. It worked OK except the fact that the table is read as a list.



library(RCurl)
library(XML)
d<-getURL('https://securewordpresswebsiteAddress/data/')
d<-readHTMLTable(d, header=T)


Here is what I get after reading the table



> d
$`NULL`
ID X Y Depth P
1 1046 256857 2632323 13 2.8
2 1054 257090 2632039 13 1.1
3 1057 257099 2631981 13 2.6
4 1058 257071 2632004 9 2.1
5 1060 257173 2632004 13 4
6 1089 257194 2631660 13 14.1


Where is this $NULL coming from? is there a way to avoid it?










share|improve this question

























  • websiteAddress does not seem to resolve in my browser. it wouldn't be a site that prohibits scraping, would it?

    – hrbrmstr
    Nov 24 '18 at 2:38











  • no i gave a fictitious link, the webpage is not prohibiting scraping

    – ToNoY
    Nov 24 '18 at 2:42











  • Someone else will likely take your word for it.

    – hrbrmstr
    Nov 24 '18 at 2:55














0












0








0








I want to read a table directly from a webpage with R. In reader's view the webpage with the table looks like this:



enter image description here



I used two packages to read the table from the webpage. It worked OK except the fact that the table is read as a list.



library(RCurl)
library(XML)
d<-getURL('https://securewordpresswebsiteAddress/data/')
d<-readHTMLTable(d, header=T)


Here is what I get after reading the table



> d
$`NULL`
ID X Y Depth P
1 1046 256857 2632323 13 2.8
2 1054 257090 2632039 13 1.1
3 1057 257099 2631981 13 2.6
4 1058 257071 2632004 9 2.1
5 1060 257173 2632004 13 4
6 1089 257194 2631660 13 14.1


Where is this $NULL coming from? is there a way to avoid it?










share|improve this question
















I want to read a table directly from a webpage with R. In reader's view the webpage with the table looks like this:



enter image description here



I used two packages to read the table from the webpage. It worked OK except the fact that the table is read as a list.



library(RCurl)
library(XML)
d<-getURL('https://securewordpresswebsiteAddress/data/')
d<-readHTMLTable(d, header=T)


Here is what I get after reading the table



> d
$`NULL`
ID X Y Depth P
1 1046 256857 2632323 13 2.8
2 1054 257090 2632039 13 1.1
3 1057 257099 2631981 13 2.6
4 1058 257071 2632004 9 2.1
5 1060 257173 2632004 13 4
6 1089 257194 2631660 13 14.1


Where is this $NULL coming from? is there a way to avoid it?







html r web






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 2:46







ToNoY

















asked Nov 24 '18 at 2:35









ToNoYToNoY

7011632




7011632













  • websiteAddress does not seem to resolve in my browser. it wouldn't be a site that prohibits scraping, would it?

    – hrbrmstr
    Nov 24 '18 at 2:38











  • no i gave a fictitious link, the webpage is not prohibiting scraping

    – ToNoY
    Nov 24 '18 at 2:42











  • Someone else will likely take your word for it.

    – hrbrmstr
    Nov 24 '18 at 2:55



















  • websiteAddress does not seem to resolve in my browser. it wouldn't be a site that prohibits scraping, would it?

    – hrbrmstr
    Nov 24 '18 at 2:38











  • no i gave a fictitious link, the webpage is not prohibiting scraping

    – ToNoY
    Nov 24 '18 at 2:42











  • Someone else will likely take your word for it.

    – hrbrmstr
    Nov 24 '18 at 2:55

















websiteAddress does not seem to resolve in my browser. it wouldn't be a site that prohibits scraping, would it?

– hrbrmstr
Nov 24 '18 at 2:38





websiteAddress does not seem to resolve in my browser. it wouldn't be a site that prohibits scraping, would it?

– hrbrmstr
Nov 24 '18 at 2:38













no i gave a fictitious link, the webpage is not prohibiting scraping

– ToNoY
Nov 24 '18 at 2:42





no i gave a fictitious link, the webpage is not prohibiting scraping

– ToNoY
Nov 24 '18 at 2:42













Someone else will likely take your word for it.

– hrbrmstr
Nov 24 '18 at 2:55





Someone else will likely take your word for it.

– hrbrmstr
Nov 24 '18 at 2:55












1 Answer
1






active

oldest

votes


















0














Your code is actually returning a list of named elements, based on the makeup of your HTML table.



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=FALSE)
$`NULL`
$`NULL`$`ID`
[1] "1046" "1054" "1057" "1058" "1060" "1089"

$`NULL`$X
[1] "256857" "257090" "257099" "257071" "257194" "257194"

$`NULL`$Y
[1] "2632323" "2632039" "2631981" "2632004" "2632004" "2631660"

$`NULL`$Depth
[1] "13" "13" "13" "9" "13" "13"

$`NULL`$P
[1] "2.8" "1.1" "2.6" "2.1" "4" "14.1"


So when you use as.data.frame = TRUE it coerces this list of elements into another list containing a data.frame. Since the HTML table does not have an id associated to it, it is named NULL.



Fix this by adding an id inside the table tag when you write your HTML table, like so <table id='sometable'> .. </table>



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=TRUE)

$`sometable`
ID X Y Depth P
1 1046 256857 2632323 13 2.8
2 1054 257090 2632039 13 1.1
3 1057 257099 2631981 13 2.6
4 1058 257071 2632004 9 2.1
5 1060 257194 2632004 13 4
6 1089 257194 2631660 13 14.1


The HTML file I am reading contains the following table:



<table id='sometable'>
<thead>
<tr><th>ID</th><th>X</th><th>Y</th><th>Depth</th><th>P</th></tr>
</thead>
<tbody>
<tr><td>1046</td><td>256857</td><td>2632323</td><td>13</td><td>2.8</td></tr>
<tr><td>1054</td><td>257090</td><td>2632039</td><td>13</td><td>1.1</td></tr>
<tr><td>1057</td><td>257099</td><td>2631981</td><td>13</td><td>2.6</td></tr>
<tr><td>1058</td><td>257071</td><td>2632004</td><td>9</td><td>2.1</td></tr>
<tr><td>1060</td><td>257194</td><td>2632004</td><td>13</td><td>4</td></tr>
<tr><td>1089</td><td>257194</td><td>2631660</td><td>13</td><td>14.1</td></tr>
</tbody>
</table>





share|improve this answer


























  • so how to avoid that problem of "NULL" while writing HTML file?

    – ToNoY
    Nov 24 '18 at 4:40











  • To avoid this, the table should contain an id inside its tag. I adjusted my answer to show this.

    – avenger012
    Nov 24 '18 at 13:21











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454713%2freading-website-table-comes-with-a-list-name-null-in-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Your code is actually returning a list of named elements, based on the makeup of your HTML table.



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=FALSE)
$`NULL`
$`NULL`$`ID`
[1] "1046" "1054" "1057" "1058" "1060" "1089"

$`NULL`$X
[1] "256857" "257090" "257099" "257071" "257194" "257194"

$`NULL`$Y
[1] "2632323" "2632039" "2631981" "2632004" "2632004" "2631660"

$`NULL`$Depth
[1] "13" "13" "13" "9" "13" "13"

$`NULL`$P
[1] "2.8" "1.1" "2.6" "2.1" "4" "14.1"


So when you use as.data.frame = TRUE it coerces this list of elements into another list containing a data.frame. Since the HTML table does not have an id associated to it, it is named NULL.



Fix this by adding an id inside the table tag when you write your HTML table, like so <table id='sometable'> .. </table>



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=TRUE)

$`sometable`
ID X Y Depth P
1 1046 256857 2632323 13 2.8
2 1054 257090 2632039 13 1.1
3 1057 257099 2631981 13 2.6
4 1058 257071 2632004 9 2.1
5 1060 257194 2632004 13 4
6 1089 257194 2631660 13 14.1


The HTML file I am reading contains the following table:



<table id='sometable'>
<thead>
<tr><th>ID</th><th>X</th><th>Y</th><th>Depth</th><th>P</th></tr>
</thead>
<tbody>
<tr><td>1046</td><td>256857</td><td>2632323</td><td>13</td><td>2.8</td></tr>
<tr><td>1054</td><td>257090</td><td>2632039</td><td>13</td><td>1.1</td></tr>
<tr><td>1057</td><td>257099</td><td>2631981</td><td>13</td><td>2.6</td></tr>
<tr><td>1058</td><td>257071</td><td>2632004</td><td>9</td><td>2.1</td></tr>
<tr><td>1060</td><td>257194</td><td>2632004</td><td>13</td><td>4</td></tr>
<tr><td>1089</td><td>257194</td><td>2631660</td><td>13</td><td>14.1</td></tr>
</tbody>
</table>





share|improve this answer


























  • so how to avoid that problem of "NULL" while writing HTML file?

    – ToNoY
    Nov 24 '18 at 4:40











  • To avoid this, the table should contain an id inside its tag. I adjusted my answer to show this.

    – avenger012
    Nov 24 '18 at 13:21
















0














Your code is actually returning a list of named elements, based on the makeup of your HTML table.



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=FALSE)
$`NULL`
$`NULL`$`ID`
[1] "1046" "1054" "1057" "1058" "1060" "1089"

$`NULL`$X
[1] "256857" "257090" "257099" "257071" "257194" "257194"

$`NULL`$Y
[1] "2632323" "2632039" "2631981" "2632004" "2632004" "2631660"

$`NULL`$Depth
[1] "13" "13" "13" "9" "13" "13"

$`NULL`$P
[1] "2.8" "1.1" "2.6" "2.1" "4" "14.1"


So when you use as.data.frame = TRUE it coerces this list of elements into another list containing a data.frame. Since the HTML table does not have an id associated to it, it is named NULL.



Fix this by adding an id inside the table tag when you write your HTML table, like so <table id='sometable'> .. </table>



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=TRUE)

$`sometable`
ID X Y Depth P
1 1046 256857 2632323 13 2.8
2 1054 257090 2632039 13 1.1
3 1057 257099 2631981 13 2.6
4 1058 257071 2632004 9 2.1
5 1060 257194 2632004 13 4
6 1089 257194 2631660 13 14.1


The HTML file I am reading contains the following table:



<table id='sometable'>
<thead>
<tr><th>ID</th><th>X</th><th>Y</th><th>Depth</th><th>P</th></tr>
</thead>
<tbody>
<tr><td>1046</td><td>256857</td><td>2632323</td><td>13</td><td>2.8</td></tr>
<tr><td>1054</td><td>257090</td><td>2632039</td><td>13</td><td>1.1</td></tr>
<tr><td>1057</td><td>257099</td><td>2631981</td><td>13</td><td>2.6</td></tr>
<tr><td>1058</td><td>257071</td><td>2632004</td><td>9</td><td>2.1</td></tr>
<tr><td>1060</td><td>257194</td><td>2632004</td><td>13</td><td>4</td></tr>
<tr><td>1089</td><td>257194</td><td>2631660</td><td>13</td><td>14.1</td></tr>
</tbody>
</table>





share|improve this answer


























  • so how to avoid that problem of "NULL" while writing HTML file?

    – ToNoY
    Nov 24 '18 at 4:40











  • To avoid this, the table should contain an id inside its tag. I adjusted my answer to show this.

    – avenger012
    Nov 24 '18 at 13:21














0












0








0







Your code is actually returning a list of named elements, based on the makeup of your HTML table.



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=FALSE)
$`NULL`
$`NULL`$`ID`
[1] "1046" "1054" "1057" "1058" "1060" "1089"

$`NULL`$X
[1] "256857" "257090" "257099" "257071" "257194" "257194"

$`NULL`$Y
[1] "2632323" "2632039" "2631981" "2632004" "2632004" "2631660"

$`NULL`$Depth
[1] "13" "13" "13" "9" "13" "13"

$`NULL`$P
[1] "2.8" "1.1" "2.6" "2.1" "4" "14.1"


So when you use as.data.frame = TRUE it coerces this list of elements into another list containing a data.frame. Since the HTML table does not have an id associated to it, it is named NULL.



Fix this by adding an id inside the table tag when you write your HTML table, like so <table id='sometable'> .. </table>



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=TRUE)

$`sometable`
ID X Y Depth P
1 1046 256857 2632323 13 2.8
2 1054 257090 2632039 13 1.1
3 1057 257099 2631981 13 2.6
4 1058 257071 2632004 9 2.1
5 1060 257194 2632004 13 4
6 1089 257194 2631660 13 14.1


The HTML file I am reading contains the following table:



<table id='sometable'>
<thead>
<tr><th>ID</th><th>X</th><th>Y</th><th>Depth</th><th>P</th></tr>
</thead>
<tbody>
<tr><td>1046</td><td>256857</td><td>2632323</td><td>13</td><td>2.8</td></tr>
<tr><td>1054</td><td>257090</td><td>2632039</td><td>13</td><td>1.1</td></tr>
<tr><td>1057</td><td>257099</td><td>2631981</td><td>13</td><td>2.6</td></tr>
<tr><td>1058</td><td>257071</td><td>2632004</td><td>9</td><td>2.1</td></tr>
<tr><td>1060</td><td>257194</td><td>2632004</td><td>13</td><td>4</td></tr>
<tr><td>1089</td><td>257194</td><td>2631660</td><td>13</td><td>14.1</td></tr>
</tbody>
</table>





share|improve this answer















Your code is actually returning a list of named elements, based on the makeup of your HTML table.



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=FALSE)
$`NULL`
$`NULL`$`ID`
[1] "1046" "1054" "1057" "1058" "1060" "1089"

$`NULL`$X
[1] "256857" "257090" "257099" "257071" "257194" "257194"

$`NULL`$Y
[1] "2632323" "2632039" "2631981" "2632004" "2632004" "2631660"

$`NULL`$Depth
[1] "13" "13" "13" "9" "13" "13"

$`NULL`$P
[1] "2.8" "1.1" "2.6" "2.1" "4" "14.1"


So when you use as.data.frame = TRUE it coerces this list of elements into another list containing a data.frame. Since the HTML table does not have an id associated to it, it is named NULL.



Fix this by adding an id inside the table tag when you write your HTML table, like so <table id='sometable'> .. </table>



> readHTMLTable('~/htmltest.html', header=TRUE, as.data.frame=TRUE)

$`sometable`
ID X Y Depth P
1 1046 256857 2632323 13 2.8
2 1054 257090 2632039 13 1.1
3 1057 257099 2631981 13 2.6
4 1058 257071 2632004 9 2.1
5 1060 257194 2632004 13 4
6 1089 257194 2631660 13 14.1


The HTML file I am reading contains the following table:



<table id='sometable'>
<thead>
<tr><th>ID</th><th>X</th><th>Y</th><th>Depth</th><th>P</th></tr>
</thead>
<tbody>
<tr><td>1046</td><td>256857</td><td>2632323</td><td>13</td><td>2.8</td></tr>
<tr><td>1054</td><td>257090</td><td>2632039</td><td>13</td><td>1.1</td></tr>
<tr><td>1057</td><td>257099</td><td>2631981</td><td>13</td><td>2.6</td></tr>
<tr><td>1058</td><td>257071</td><td>2632004</td><td>9</td><td>2.1</td></tr>
<tr><td>1060</td><td>257194</td><td>2632004</td><td>13</td><td>4</td></tr>
<tr><td>1089</td><td>257194</td><td>2631660</td><td>13</td><td>14.1</td></tr>
</tbody>
</table>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 13:20

























answered Nov 24 '18 at 3:01









avenger012avenger012

31319




31319













  • so how to avoid that problem of "NULL" while writing HTML file?

    – ToNoY
    Nov 24 '18 at 4:40











  • To avoid this, the table should contain an id inside its tag. I adjusted my answer to show this.

    – avenger012
    Nov 24 '18 at 13:21



















  • so how to avoid that problem of "NULL" while writing HTML file?

    – ToNoY
    Nov 24 '18 at 4:40











  • To avoid this, the table should contain an id inside its tag. I adjusted my answer to show this.

    – avenger012
    Nov 24 '18 at 13:21

















so how to avoid that problem of "NULL" while writing HTML file?

– ToNoY
Nov 24 '18 at 4:40





so how to avoid that problem of "NULL" while writing HTML file?

– ToNoY
Nov 24 '18 at 4:40













To avoid this, the table should contain an id inside its tag. I adjusted my answer to show this.

– avenger012
Nov 24 '18 at 13:21





To avoid this, the table should contain an id inside its tag. I adjusted my answer to show this.

– avenger012
Nov 24 '18 at 13:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454713%2freading-website-table-comes-with-a-list-name-null-in-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Fiat S.p.A.

Type 'String' is not a subtype of type 'int' of 'index'