Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ampersands not escaped in xml export #234

Closed
bokov opened this issue Oct 4, 2019 · 0 comments · Fixed by #249
Closed

Ampersands not escaped in xml export #234

bokov opened this issue Oct 4, 2019 · 0 comments · Fixed by #249
Labels

Comments

@bokov
Copy link
Contributor

@bokov bokov commented Oct 4, 2019

Please specify whether your issue is about:

  • a possible bug
  • a question about package functionality
  • a suggested code or documentation change, improvement to the code, or feature request

If you are reporting (1) a bug or (2) a question about code, please supply:

  • a fully reproducible example using a publicly available dataset (or provide your data)
  • if an error is occurring, include the output of traceback() run immediately after the error occurs
12: stop(list(message = "EntityRef: expecting ';' [23]", call = doc_parse_raw(x, 
        encoding = encoding, base_url = base_url, as_html = as_html, 
        options = options), cppstack = list(file = "", line = -1L, 
        stack = c("/home/a/R/x86_64-pc-linux-gnu-library/3.4/xml2/libs/xml2.so(+0x18dcf) [0x7fa412210dcf]", 
        "/home/a/R/x86_64-pc-linux-gnu-library/3.4/xml2/libs/xml2.so(+0x234c5) [0x7fa41221b4c5]", 
        "/home/a/R/x86_64-pc-linux-gnu-library/3.4/xml2/libs/xml2.so(+0x22fe0) [0x7fa41221afe0]", 
        "/usr/lib/x86_64-linux-gnu/libxml2.so.2(__xmlRaiseError+0x38b) [0x7fa411ec5fab]", 
        "/usr/lib/x86_64-linux-gnu/libxml2.so.2(+0x38c27) [0x7fa411ec9c27]", 
        "/usr/lib/x86_64-linux-gnu/libxml2.so.2(xmlParseEntityRef+0x14f) [0x7fa411ed094f]", 
        "/usr/lib/x86_64-linux-gnu/libxml2.so.2(xmlParseReference+0x6f) [0x7fa411edc9ff]", 
        "/usr/lib/x86_64-linux-gnu/libxml2.so.2(xmlParseContent+0x170) [0x7fa411edd450]", 
        "/usr/lib/x86_64-linux-gnu/libxml2.so.2(xmlParseElement+0x153) [0x7fa411eddcc3]", 
        "/usr/lib/x86_64-linux-gnu/libxml2.so.2(xmlParseDocument+0x2c2) [0x7fa411ede2f2]", 
        "/usr/lib/x86_64-linux-gnu/libxml2.so.2(+0x4d707) [0x7fa411ede707]", 
        "/home/a/R/x86_64-pc-linux-gnu-library/3.4/xml2/libs/xml2.so(+0x2114b) [0x7fa41221914b]", 
        "/home/a/R/x86_64-pc-linux-gnu-library/3.4/xml2/libs/xml2.so(_xml2_doc_parse_raw+0x17e) [0x7fa41220fcae]", 
        "/usr/lib/R/lib/libR.so(+0xd6bdd) [0x7fa4374a2bdd]", "/usr/lib/R/lib/libR.so(Rf_eval+0x7b1) [0x7fa4374e7271]", 
        "/usr/lib/R/lib/libR.so(+0x11d94c) [0x7fa4374e994c]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(Rf_eval+0x32c) [0x7fa4374e6dec]", 
        "/usr/lib/R/lib/libR.so(+0x11ea3e) [0x7fa4374eaa3e]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11d94c) [0x7fa4374e994c]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(Rf_eval+0x32c) [0x7fa4374e6dec]", 
        "/usr/lib/R/lib/libR.so(+0x11d94c) [0x7fa4374e994c]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11d94c) [0x7fa4374e994c]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(+0x151554) [0x7fa43751d554]", 
        "/usr/lib/R/lib/libR.so(+0x151990) [0x7fa43751d990]", "/usr/lib/R/lib/libR.so(+0x151cb4) [0x7fa43751dcb4]", 
        "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11d94c) [0x7fa4374e994c]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(+0x112d74) [0x7fa4374ded74]", 
        "/usr/lib/R/lib/libR.so(Rf_eval+0x170) [0x7fa4374e6c30]", 
        "/usr/lib/R/lib/libR.so(+0x11b576) [0x7fa4374e7576]", "/usr/lib/R/lib/libR.so(Rf_eval+0x817) [0x7fa4374e72d7]", 
        "/usr/lib/R/lib/libR.so(+0x11b576) [0x7fa4374e7576]", "/usr/lib/R/lib/libR.so(+0x11955a) [0x7fa4374e555a]", 
        "/usr/lib/R/lib/libR.so(Rf_eval+0x170) [0x7fa4374e6c30]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(Rf_eval+0x32c) [0x7fa4374e6dec]", 
        "/usr/lib/R/lib/libR.so(+0x11ea3e) [0x7fa4374eaa3e]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11d94c) [0x7fa4374e994c]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(+0x151554) [0x7fa43751d554]", 
        "/usr/lib/R/lib/libR.so(+0x151990) [0x7fa43751d990]", "/usr/lib/R/lib/libR.so(+0x151cb4) [0x7fa43751dcb4]", 
        "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11d94c) [0x7fa4374e994c]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(+0x112d74) [0x7fa4374ded74]", 
        "/usr/lib/R/lib/libR.so(Rf_eval+0x170) [0x7fa4374e6c30]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(+0x151554) [0x7fa43751d554]", 
        "/usr/lib/R/lib/libR.so(+0x151990) [0x7fa43751d990]", "/usr/lib/R/lib/libR.so(+0x151cb4) [0x7fa43751dcb4]", 
        "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11d94c) [0x7fa4374e994c]", "/usr/lib/R/lib/libR.so(Rf_eval+0x585) [0x7fa4374e7045]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(+0x112d74) [0x7fa4374ded74]", 
        "/usr/lib/R/lib/libR.so(Rf_eval+0x170) [0x7fa4374e6c30]", 
        "/usr/lib/R/lib/libR.so(+0x11cc2f) [0x7fa4374e8c2f]", "/usr/lib/R/lib/libR.so(Rf_eval+0x32c) [0x7fa4374e6dec]", 
        "/usr/lib/R/lib/libR.so(Rf_ReplIteration+0x232) [0x7fa437510152]", 
        "/usr/lib/R/lib/libR.so(+0x144531) [0x7fa437510531]", "/usr/lib/R/lib/libR.so(run_Rmainloop+0x4f) [0x7fa4375105ef]", 
        "/usr/lib/rstudio/bin/rsession(rstudio::r::session::runEmbeddedR(rstudio::core::FilePath const&, rstudio::core::FilePath const&, bool, bool, SA_TYPE, rstudio::r::session::Callbacks const&, rstudio::r::session::InternalCallbacks*)+0x1b2) [0xec72f2]", 
        "/usr/lib/rstudio/bin/rsession(rstudio::r::session::run(rstudio::r::session::ROptions const&, rstudio::r::session::RCallbacks const&)+0x252d) [0xea682d]", 
        "/usr/lib/rstudio/bin/rsession(main+0x33cf) [0x70645f]", 
        "/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7fa435b72f45]", 
        "/usr/lib/rstudio/bin/rsession() [0x7173f5]"))))
11: .Call(`_xml2_doc_parse_raw`, x, encoding, base_url, as_html, 
        options)
10: doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html = as_html, 
        options = options)
9: read_xml.raw(charToRaw(enc2utf8(x)), "UTF-8", ..., as_html = as_html, 
       options = options)
8: read_xml.character(paste0(twrap(x[i, j, drop = TRUE], names(x)[j]), 
       "\n"))
7: xml2::read_xml(paste0(twrap(x[i, j, drop = TRUE], names(x)[j]), 
       "\n")) at export_methods.R#284
6: create_node(.value, .x, .copy = .copy, ...)
5: xml_add_child.xml_node(thisrow, xml2::read_xml(paste0(twrap(x[i, 
       j, drop = TRUE], names(x)[j]), "\n")))
4: xml2::xml_add_child(thisrow, xml2::read_xml(paste0(twrap(x[i, 
       j, drop = TRUE], names(x)[j]), "\n"))) at export_methods.R#284
3: .export.rio_xml(file = file, x = x, ...) at extensions.R#53
2: .export(file = file, x = x, ...) at export.R#147
1: export(bar, "bar.xml")
  • the output of sessionInfo()

Put your code here:

## load package
library("rio")

## code goes here
# set up example data frames
bar <- foo <- as.data.frame(matrix(letters[1:24],nrow=6),stringsAsFactors = F);
# into the second one introduce an ampersand
bar[6,3] <- "r&d";
# foo saves successfully
export(foo,"foo.xml");
# bar, which differs from foo only by an embedded ampersand, errors
export(bar,"bar.xml");
# remove the ampersand and it works again
export(bar[-6,],"bar1.xml");
export(bar[,-3],"bar2.xml");


## session info for your system
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.6 LTS

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/lapack/liblapack.so.3.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rio_0.5.20     testthat_2.2.1

loaded via a namespace (and not attached):
 [1] zip_2.0.4           Rcpp_1.0.2          compiler_3.4.4      pillar_1.4.2       
 [5] cellranger_1.1.0    prettyunits_1.0.2   forcats_0.3.0       remotes_2.1.0      
 [9] tools_3.4.4         digest_0.6.21       pkgbuild_1.0.5      pkgload_1.0.2      
[13] memoise_1.1.0       tibble_2.1.3        pkgconfig_2.0.3     rlang_0.4.0        
[17] openxlsx_4.1.0.1    cli_1.1.0           rstudioapi_0.10     curl_4.2           
[21] yaml_2.2.0          haven_2.1.1         xml2_1.2.2          withr_2.1.2        
[25] desc_1.2.0          fs_1.3.1            devtools_2.2.1.9000 hms_0.4.2          
[29] rprojroot_1.3-2     glue_1.3.1          data.table_1.12.4   R6_2.4.0           
[33] processx_3.4.1      readxl_1.3.1        foreign_0.8-70      sessioninfo_1.1.1  
[37] callr_3.3.2         magrittr_1.5        backports_1.1.2     ps_1.3.0           
[41] ellipsis_0.3.0      usethis_1.5.1       assertthat_0.2.1    crayon_1.3.4
bokov added a commit to bokov/rio that referenced this issue Dec 3, 2019
… headers for XML where '&' and ' ' both get replaced by '.'. Fixes leeper#234
@leeper leeper closed this in #249 Dec 17, 2019
leeper added a commit that referenced this issue Dec 17, 2019
… headers for XML where '&' and ' ' both get replaced by '.'. Fixes #234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.