0

I have a list in a variable named api_result which returns the following output in the console when calling it:

> api_result
{xml_nodeset (200)}
 [1] <visitor_activity>\n  <id>136212161</id>\n  <prospect_id>2680070</prospect_id>\n  <type>6</type>\n  <type_name>Email</type_name>\n  <det ...
 [2] <visitor_activity>\n  <id>136212163</id>\n  <prospect_id>21304456</prospect_id>\n  <type>6</type>\n  <type_name>Email</type_name>\n  <de ...
etc...

I want to append to api_result a second list named api_result2 which has the same length and structure.

When using the c() function, the output in the console seems to have changed when calling api_result:

> api_result <- c(api_result,api_result2)
> api_result
[[1]]
{xml_node}
<visitor_activity>
[1] <id>136212161</id>
[2] <prospect_id>2680070</prospect_id>
[3] <type>6</type>
[4] <type_name>Email</type_name>

The problem I'm having with this is that the following code was working fine on the api_result:

prospect_ids <- xml_text(xml_find_all(api_result, "//prospect_id"))

But now it's failing, and returns the following error:

Error in UseMethod("xml_find_all") : 
  no applicable method for 'xml_find_all' applied to an object of class "list"

How can I ensure that the structure of the list is maintained, so that my xml_find_all() function keeps working?

BroQ
  • 101
  • 6
  • `lapply(api_result,function(x){xml_text(xml_find_all(x,"//prospect_id"))}`? – CrunchyTopping Aug 06 '19 at 21:13
  • Thanks, but is there a reason why the original structure is getting lost? Isn't there a way to keep the structure in tact? – BroQ Aug 08 '19 at 07:43
  • Dunno. Does creating two separate lists then using [this](https://stackoverflow.com/questions/14848172/appending-a-list-to-a-list-of-lists-in-r) help? – CrunchyTopping Aug 08 '19 at 12:07

0 Answers0