Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Fatma
New Member

Failed to load R script

I have this R script and he run succefully but when i would to load in Power BI, i get that error message:

this is my code: 

library(rvest)
> library(httr)
> sess <- html_session("http://www.atb.com.tn/", user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.39 Safari/537.36"))
> pg <- jump_to(sess, "http://www.atb.com.tn/devise")
> dat <- content(pg$response, as="parsed")
> mydata= html_table(html_nodes(dat, "table")[[2]], header=TRUE)

And that the error message:

 

 

Détails : « ADO.NET : Erreur du script R.
Le chargement a nÚcessitÚ le package : xml2
Error in as.vector(x, "list") :
cannot coerce type 'environment' to vector of type 'list'
Calls: html_table ... <Anonymous> -> lapply -> as.list -> as.list.default
ExÚcution arrÛtÚe

5 REPLIES 5
ankitpatira
Community Champion
Community Champion

@Fatma @beno

 

Adding library(methods) reference has worked. Since data frame returned has duplicate column names it would again error out so changed header to False (it will return header as first row and you can again change that to headers in power bi) and also fill = True. so end script which works will be as follows,

 

library(rvest)
library(methods)
library(httr)
sess <- html_session("http://www.atb.com.tn/", user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.39 Safari/537.36"))
pg <- jump_to(sess, "http://www.atb.com.tn/devise")
dat <- content(pg$response, as="parsed")
mydata= html_table(html_nodes(dat, "table")[[2]], header=FALSE, fill=TRUE)

Many thanks

beno
Frequent Visitor

Hi, 

 

Any news about this issue, as I have the same error message:

 

Details: "ADO.NET: R script error.
Loading required package: xml2
Warning message:
'html' is deprecated.
Use 'read_html' instead.
See help("Deprecated") 
Error in as.vector(x, "list") : 
  cannot coerce type 'environment' to vector of type 'list'
Calls: %>% ... <Anonymous> -> lapply -> as.list -> as.list.default
Execution halted
"

 

The installation folder is:

C:\Program Files\R\R-3.3.1

 

The downloaded binary packages (add-on packages) are in:
C:\Users\dev\AppData\Local\Temp\RtmpCYKMBC\downloaded_packages

 

The '.libPaths()' will give the following paths:

[1] "C:/Users/dev/Documents/R/win-library/3.3"
[2] "C:/Program Files/R/R-3.3.1/library"

 

As during installing add-on, I have chosen to have a personal library:

Would you like to use a personal library instead? Yes

 

BR

beno
Frequent Visitor

Isn't there any reply to his post?

@beno I'm not very familiar with "R", other than people like to make pirate jokes when studying and applying it. I did find this forum with a similiar question, it sounds like it could assist you.

 


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors