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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.