How to print the sign “±” in a string in R (to place this character in a table like `kableextra`)










0















I want to print a plus minus sign of the form ± into a string in R, so that I can place that string a table with kableextra



Here is the structure of the string :



x = paste0("first_string", 2, "±", 3, "second_string", collapse = "")


However I get the following output:



"first_string23022613second_string"


what should I do to have the output:



"first_string2±3second_string"


I found that 302261 is the encoding for ± in Octal Escape Sequence according to this website or this website



EDIT Here is the output of sessionInfo():



R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] C

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

other attached packages:
[1] bindrcpp_0.2.2 rms_5.1-2 SparseM_1.77 Hmisc_4.1-1 Formula_1.2-3
[6] lattice_0.20-35 blme_1.0-4 emmeans_1.2.4 lme4_1.1-18-1 Matrix_1.2-14
[11] multcomp_1.4-8 TH.data_1.0-8 MASS_7.3-49 mvtnorm_1.0-8 survminer_0.4.3
[16] survival_2.41-3 latex2exp_0.4.0 magick_1.9 cowplot_0.9.3 ggpubr_0.1.7
[21] magrittr_1.5 gridExtra_2.3 rcompanion_2.0.0 ggsignif_0.4.0 ggplot2_3.1.0
[26] chron_2.3-52 lubridate_1.7.4 dplyr_0.7.5 kableExtra_0.9.0 knitr_1.20
[31] broom_0.4.5

loaded via a namespace (and not attached):
[1] minqa_1.2.4 colorspace_1.3-2 class_7.3-14 modeltools_0.2-22
[5] rprojroot_1.3-2 estimability_1.3 htmlTable_1.12 base64enc_0.1-3
[9] rstudioapi_0.7 MatrixModels_0.4-1 manipulate_1.0.1 coin_1.2-2
[13] xml2_1.2.0 codetools_0.2-15 mnormt_1.5-5 nloptr_1.0.4
[17] km.ci_0.5-2 cluster_2.0.7-1 readr_1.1.1 compiler_3.5.0
[21] httr_1.3.1 backports_1.1.2 assertthat_0.2.0 lazyeval_0.2.1
[25] quantreg_5.36 acepack_1.4.1 htmltools_0.3.6 tools_3.5.0
[29] coda_0.19-1 gtable_0.2.0 glue_1.3.0 reshape2_1.4.3
[33] Rcpp_1.0.0 nlme_3.1-137 psych_1.8.4 lmtest_0.9-36
[37] stringr_1.3.1 rvest_0.3.2 polspline_1.1.13 zoo_1.8-2
[41] scales_1.0.0 hms_0.4.2 parallel_3.5.0 sandwich_2.4-0
[45] expm_0.999-2 RColorBrewer_1.1-2 yaml_2.1.19 BSDA_1.2.0
[49] KMsurv_0.1-5 EMT_1.1 rpart_4.1-13 latticeExtra_0.6-28
[53] stringi_1.2.4 nortest_1.0-4 e1071_1.6-8 checkmate_1.8.5
[57] boot_1.3-20 rlang_0.3.0.1 pkgconfig_2.0.1 evaluate_0.10.1
[61] purrr_0.2.5 bindr_0.1.1 labeling_0.3 htmlwidgets_1.2
[65] cmprsk_2.2-7 tidyselect_0.2.4 plyr_1.8.4 R6_2.3.0
[69] DescTools_0.99.25 multcompView_0.1-7 pillar_1.2.3 foreign_0.8-70
[73] withr_2.1.2 nnet_7.3-12 tibble_1.4.2 survMisc_0.5.5
[77] rmarkdown_1.10 grid_3.5.0 data.table_1.11.4 digest_0.6.18
[81] xtable_1.8-2 tidyr_0.8.1 stats4_3.5.0 munsell_0.5.0
[85] viridisLite_0.3.0









share|improve this question



















  • 3





    I can't replicate your result. I get "first_string2±3second_string" when testing on both R 3.4.2 and R 3.5.1.

    – thelatemail
    Nov 13 '18 at 21:51






  • 1





    Thank you @thelatemail. I have R version 3.5.0 (2018-04-23) running on macOS 10.14. I recopied the code and still get 302261 instead of ±. Any idea of what to do next / where the problem could be?

    – ecjb
    Nov 13 '18 at 21:58












  • @ecjb This is almost certainly locale-related (see some of the discussion here). Can you edit your question to include the output from sessionInfo()?

    – duckmayr
    Nov 13 '18 at 22:39











  • Thank you for your comment @duckmayr. I edited the question and copied the ouput of sessionInfo()

    – ecjb
    Nov 13 '18 at 22:44











  • @ecjb What happens if you try Sys.setlocale("LC_ALL","en_US.UTF-8"); paste0("first_string", 2, "±", 3, "second_string", collapse = "")?

    – duckmayr
    Nov 13 '18 at 22:56















0















I want to print a plus minus sign of the form ± into a string in R, so that I can place that string a table with kableextra



Here is the structure of the string :



x = paste0("first_string", 2, "±", 3, "second_string", collapse = "")


However I get the following output:



"first_string23022613second_string"


what should I do to have the output:



"first_string2±3second_string"


I found that 302261 is the encoding for ± in Octal Escape Sequence according to this website or this website



EDIT Here is the output of sessionInfo():



R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] C

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

other attached packages:
[1] bindrcpp_0.2.2 rms_5.1-2 SparseM_1.77 Hmisc_4.1-1 Formula_1.2-3
[6] lattice_0.20-35 blme_1.0-4 emmeans_1.2.4 lme4_1.1-18-1 Matrix_1.2-14
[11] multcomp_1.4-8 TH.data_1.0-8 MASS_7.3-49 mvtnorm_1.0-8 survminer_0.4.3
[16] survival_2.41-3 latex2exp_0.4.0 magick_1.9 cowplot_0.9.3 ggpubr_0.1.7
[21] magrittr_1.5 gridExtra_2.3 rcompanion_2.0.0 ggsignif_0.4.0 ggplot2_3.1.0
[26] chron_2.3-52 lubridate_1.7.4 dplyr_0.7.5 kableExtra_0.9.0 knitr_1.20
[31] broom_0.4.5

loaded via a namespace (and not attached):
[1] minqa_1.2.4 colorspace_1.3-2 class_7.3-14 modeltools_0.2-22
[5] rprojroot_1.3-2 estimability_1.3 htmlTable_1.12 base64enc_0.1-3
[9] rstudioapi_0.7 MatrixModels_0.4-1 manipulate_1.0.1 coin_1.2-2
[13] xml2_1.2.0 codetools_0.2-15 mnormt_1.5-5 nloptr_1.0.4
[17] km.ci_0.5-2 cluster_2.0.7-1 readr_1.1.1 compiler_3.5.0
[21] httr_1.3.1 backports_1.1.2 assertthat_0.2.0 lazyeval_0.2.1
[25] quantreg_5.36 acepack_1.4.1 htmltools_0.3.6 tools_3.5.0
[29] coda_0.19-1 gtable_0.2.0 glue_1.3.0 reshape2_1.4.3
[33] Rcpp_1.0.0 nlme_3.1-137 psych_1.8.4 lmtest_0.9-36
[37] stringr_1.3.1 rvest_0.3.2 polspline_1.1.13 zoo_1.8-2
[41] scales_1.0.0 hms_0.4.2 parallel_3.5.0 sandwich_2.4-0
[45] expm_0.999-2 RColorBrewer_1.1-2 yaml_2.1.19 BSDA_1.2.0
[49] KMsurv_0.1-5 EMT_1.1 rpart_4.1-13 latticeExtra_0.6-28
[53] stringi_1.2.4 nortest_1.0-4 e1071_1.6-8 checkmate_1.8.5
[57] boot_1.3-20 rlang_0.3.0.1 pkgconfig_2.0.1 evaluate_0.10.1
[61] purrr_0.2.5 bindr_0.1.1 labeling_0.3 htmlwidgets_1.2
[65] cmprsk_2.2-7 tidyselect_0.2.4 plyr_1.8.4 R6_2.3.0
[69] DescTools_0.99.25 multcompView_0.1-7 pillar_1.2.3 foreign_0.8-70
[73] withr_2.1.2 nnet_7.3-12 tibble_1.4.2 survMisc_0.5.5
[77] rmarkdown_1.10 grid_3.5.0 data.table_1.11.4 digest_0.6.18
[81] xtable_1.8-2 tidyr_0.8.1 stats4_3.5.0 munsell_0.5.0
[85] viridisLite_0.3.0









share|improve this question



















  • 3





    I can't replicate your result. I get "first_string2±3second_string" when testing on both R 3.4.2 and R 3.5.1.

    – thelatemail
    Nov 13 '18 at 21:51






  • 1





    Thank you @thelatemail. I have R version 3.5.0 (2018-04-23) running on macOS 10.14. I recopied the code and still get 302261 instead of ±. Any idea of what to do next / where the problem could be?

    – ecjb
    Nov 13 '18 at 21:58












  • @ecjb This is almost certainly locale-related (see some of the discussion here). Can you edit your question to include the output from sessionInfo()?

    – duckmayr
    Nov 13 '18 at 22:39











  • Thank you for your comment @duckmayr. I edited the question and copied the ouput of sessionInfo()

    – ecjb
    Nov 13 '18 at 22:44











  • @ecjb What happens if you try Sys.setlocale("LC_ALL","en_US.UTF-8"); paste0("first_string", 2, "±", 3, "second_string", collapse = "")?

    – duckmayr
    Nov 13 '18 at 22:56













0












0








0


1






I want to print a plus minus sign of the form ± into a string in R, so that I can place that string a table with kableextra



Here is the structure of the string :



x = paste0("first_string", 2, "±", 3, "second_string", collapse = "")


However I get the following output:



"first_string23022613second_string"


what should I do to have the output:



"first_string2±3second_string"


I found that 302261 is the encoding for ± in Octal Escape Sequence according to this website or this website



EDIT Here is the output of sessionInfo():



R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] C

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

other attached packages:
[1] bindrcpp_0.2.2 rms_5.1-2 SparseM_1.77 Hmisc_4.1-1 Formula_1.2-3
[6] lattice_0.20-35 blme_1.0-4 emmeans_1.2.4 lme4_1.1-18-1 Matrix_1.2-14
[11] multcomp_1.4-8 TH.data_1.0-8 MASS_7.3-49 mvtnorm_1.0-8 survminer_0.4.3
[16] survival_2.41-3 latex2exp_0.4.0 magick_1.9 cowplot_0.9.3 ggpubr_0.1.7
[21] magrittr_1.5 gridExtra_2.3 rcompanion_2.0.0 ggsignif_0.4.0 ggplot2_3.1.0
[26] chron_2.3-52 lubridate_1.7.4 dplyr_0.7.5 kableExtra_0.9.0 knitr_1.20
[31] broom_0.4.5

loaded via a namespace (and not attached):
[1] minqa_1.2.4 colorspace_1.3-2 class_7.3-14 modeltools_0.2-22
[5] rprojroot_1.3-2 estimability_1.3 htmlTable_1.12 base64enc_0.1-3
[9] rstudioapi_0.7 MatrixModels_0.4-1 manipulate_1.0.1 coin_1.2-2
[13] xml2_1.2.0 codetools_0.2-15 mnormt_1.5-5 nloptr_1.0.4
[17] km.ci_0.5-2 cluster_2.0.7-1 readr_1.1.1 compiler_3.5.0
[21] httr_1.3.1 backports_1.1.2 assertthat_0.2.0 lazyeval_0.2.1
[25] quantreg_5.36 acepack_1.4.1 htmltools_0.3.6 tools_3.5.0
[29] coda_0.19-1 gtable_0.2.0 glue_1.3.0 reshape2_1.4.3
[33] Rcpp_1.0.0 nlme_3.1-137 psych_1.8.4 lmtest_0.9-36
[37] stringr_1.3.1 rvest_0.3.2 polspline_1.1.13 zoo_1.8-2
[41] scales_1.0.0 hms_0.4.2 parallel_3.5.0 sandwich_2.4-0
[45] expm_0.999-2 RColorBrewer_1.1-2 yaml_2.1.19 BSDA_1.2.0
[49] KMsurv_0.1-5 EMT_1.1 rpart_4.1-13 latticeExtra_0.6-28
[53] stringi_1.2.4 nortest_1.0-4 e1071_1.6-8 checkmate_1.8.5
[57] boot_1.3-20 rlang_0.3.0.1 pkgconfig_2.0.1 evaluate_0.10.1
[61] purrr_0.2.5 bindr_0.1.1 labeling_0.3 htmlwidgets_1.2
[65] cmprsk_2.2-7 tidyselect_0.2.4 plyr_1.8.4 R6_2.3.0
[69] DescTools_0.99.25 multcompView_0.1-7 pillar_1.2.3 foreign_0.8-70
[73] withr_2.1.2 nnet_7.3-12 tibble_1.4.2 survMisc_0.5.5
[77] rmarkdown_1.10 grid_3.5.0 data.table_1.11.4 digest_0.6.18
[81] xtable_1.8-2 tidyr_0.8.1 stats4_3.5.0 munsell_0.5.0
[85] viridisLite_0.3.0









share|improve this question
















I want to print a plus minus sign of the form ± into a string in R, so that I can place that string a table with kableextra



Here is the structure of the string :



x = paste0("first_string", 2, "±", 3, "second_string", collapse = "")


However I get the following output:



"first_string23022613second_string"


what should I do to have the output:



"first_string2±3second_string"


I found that 302261 is the encoding for ± in Octal Escape Sequence according to this website or this website



EDIT Here is the output of sessionInfo():



R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] C

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

other attached packages:
[1] bindrcpp_0.2.2 rms_5.1-2 SparseM_1.77 Hmisc_4.1-1 Formula_1.2-3
[6] lattice_0.20-35 blme_1.0-4 emmeans_1.2.4 lme4_1.1-18-1 Matrix_1.2-14
[11] multcomp_1.4-8 TH.data_1.0-8 MASS_7.3-49 mvtnorm_1.0-8 survminer_0.4.3
[16] survival_2.41-3 latex2exp_0.4.0 magick_1.9 cowplot_0.9.3 ggpubr_0.1.7
[21] magrittr_1.5 gridExtra_2.3 rcompanion_2.0.0 ggsignif_0.4.0 ggplot2_3.1.0
[26] chron_2.3-52 lubridate_1.7.4 dplyr_0.7.5 kableExtra_0.9.0 knitr_1.20
[31] broom_0.4.5

loaded via a namespace (and not attached):
[1] minqa_1.2.4 colorspace_1.3-2 class_7.3-14 modeltools_0.2-22
[5] rprojroot_1.3-2 estimability_1.3 htmlTable_1.12 base64enc_0.1-3
[9] rstudioapi_0.7 MatrixModels_0.4-1 manipulate_1.0.1 coin_1.2-2
[13] xml2_1.2.0 codetools_0.2-15 mnormt_1.5-5 nloptr_1.0.4
[17] km.ci_0.5-2 cluster_2.0.7-1 readr_1.1.1 compiler_3.5.0
[21] httr_1.3.1 backports_1.1.2 assertthat_0.2.0 lazyeval_0.2.1
[25] quantreg_5.36 acepack_1.4.1 htmltools_0.3.6 tools_3.5.0
[29] coda_0.19-1 gtable_0.2.0 glue_1.3.0 reshape2_1.4.3
[33] Rcpp_1.0.0 nlme_3.1-137 psych_1.8.4 lmtest_0.9-36
[37] stringr_1.3.1 rvest_0.3.2 polspline_1.1.13 zoo_1.8-2
[41] scales_1.0.0 hms_0.4.2 parallel_3.5.0 sandwich_2.4-0
[45] expm_0.999-2 RColorBrewer_1.1-2 yaml_2.1.19 BSDA_1.2.0
[49] KMsurv_0.1-5 EMT_1.1 rpart_4.1-13 latticeExtra_0.6-28
[53] stringi_1.2.4 nortest_1.0-4 e1071_1.6-8 checkmate_1.8.5
[57] boot_1.3-20 rlang_0.3.0.1 pkgconfig_2.0.1 evaluate_0.10.1
[61] purrr_0.2.5 bindr_0.1.1 labeling_0.3 htmlwidgets_1.2
[65] cmprsk_2.2-7 tidyselect_0.2.4 plyr_1.8.4 R6_2.3.0
[69] DescTools_0.99.25 multcompView_0.1-7 pillar_1.2.3 foreign_0.8-70
[73] withr_2.1.2 nnet_7.3-12 tibble_1.4.2 survMisc_0.5.5
[77] rmarkdown_1.10 grid_3.5.0 data.table_1.11.4 digest_0.6.18
[81] xtable_1.8-2 tidyr_0.8.1 stats4_3.5.0 munsell_0.5.0
[85] viridisLite_0.3.0






r character-encoding special-characters kableextra






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 22:58







ecjb

















asked Nov 13 '18 at 21:46









ecjbecjb

306114




306114







  • 3





    I can't replicate your result. I get "first_string2±3second_string" when testing on both R 3.4.2 and R 3.5.1.

    – thelatemail
    Nov 13 '18 at 21:51






  • 1





    Thank you @thelatemail. I have R version 3.5.0 (2018-04-23) running on macOS 10.14. I recopied the code and still get 302261 instead of ±. Any idea of what to do next / where the problem could be?

    – ecjb
    Nov 13 '18 at 21:58












  • @ecjb This is almost certainly locale-related (see some of the discussion here). Can you edit your question to include the output from sessionInfo()?

    – duckmayr
    Nov 13 '18 at 22:39











  • Thank you for your comment @duckmayr. I edited the question and copied the ouput of sessionInfo()

    – ecjb
    Nov 13 '18 at 22:44











  • @ecjb What happens if you try Sys.setlocale("LC_ALL","en_US.UTF-8"); paste0("first_string", 2, "±", 3, "second_string", collapse = "")?

    – duckmayr
    Nov 13 '18 at 22:56












  • 3





    I can't replicate your result. I get "first_string2±3second_string" when testing on both R 3.4.2 and R 3.5.1.

    – thelatemail
    Nov 13 '18 at 21:51






  • 1





    Thank you @thelatemail. I have R version 3.5.0 (2018-04-23) running on macOS 10.14. I recopied the code and still get 302261 instead of ±. Any idea of what to do next / where the problem could be?

    – ecjb
    Nov 13 '18 at 21:58












  • @ecjb This is almost certainly locale-related (see some of the discussion here). Can you edit your question to include the output from sessionInfo()?

    – duckmayr
    Nov 13 '18 at 22:39











  • Thank you for your comment @duckmayr. I edited the question and copied the ouput of sessionInfo()

    – ecjb
    Nov 13 '18 at 22:44











  • @ecjb What happens if you try Sys.setlocale("LC_ALL","en_US.UTF-8"); paste0("first_string", 2, "±", 3, "second_string", collapse = "")?

    – duckmayr
    Nov 13 '18 at 22:56







3




3





I can't replicate your result. I get "first_string2±3second_string" when testing on both R 3.4.2 and R 3.5.1.

– thelatemail
Nov 13 '18 at 21:51





I can't replicate your result. I get "first_string2±3second_string" when testing on both R 3.4.2 and R 3.5.1.

– thelatemail
Nov 13 '18 at 21:51




1




1





Thank you @thelatemail. I have R version 3.5.0 (2018-04-23) running on macOS 10.14. I recopied the code and still get 302261 instead of ±. Any idea of what to do next / where the problem could be?

– ecjb
Nov 13 '18 at 21:58






Thank you @thelatemail. I have R version 3.5.0 (2018-04-23) running on macOS 10.14. I recopied the code and still get 302261 instead of ±. Any idea of what to do next / where the problem could be?

– ecjb
Nov 13 '18 at 21:58














@ecjb This is almost certainly locale-related (see some of the discussion here). Can you edit your question to include the output from sessionInfo()?

– duckmayr
Nov 13 '18 at 22:39





@ecjb This is almost certainly locale-related (see some of the discussion here). Can you edit your question to include the output from sessionInfo()?

– duckmayr
Nov 13 '18 at 22:39













Thank you for your comment @duckmayr. I edited the question and copied the ouput of sessionInfo()

– ecjb
Nov 13 '18 at 22:44





Thank you for your comment @duckmayr. I edited the question and copied the ouput of sessionInfo()

– ecjb
Nov 13 '18 at 22:44













@ecjb What happens if you try Sys.setlocale("LC_ALL","en_US.UTF-8"); paste0("first_string", 2, "±", 3, "second_string", collapse = "")?

– duckmayr
Nov 13 '18 at 22:56





@ecjb What happens if you try Sys.setlocale("LC_ALL","en_US.UTF-8"); paste0("first_string", 2, "±", 3, "second_string", collapse = "")?

– duckmayr
Nov 13 '18 at 22:56












1 Answer
1






active

oldest

votes


















2














Locale settings control character sets for input and output. You have



locale:
[1] C


but if you want to print non-ASCII characters such as ±, you'll need something such as UTF-8. One example of how to accomplish this (which seems to have solved your issue per the comments) is



Sys.setlocale("LC_ALL","en_US.UTF-8")
paste0("first_string", 2, "±", 3, "second_string", collapse = "")


which should output



[1] "first_string2±3second_string"


For further information, I'd check out the following sources as a starting point:



  • R help page for getting or setting the locale

  • RStudio support on character encoding


  • readr's locale vignette





share|improve this answer






















    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%2f53289992%2fhow-to-print-the-sign-%25c2%25b1-in-a-string-in-r-to-place-this-character-in-a-table-l%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









    2














    Locale settings control character sets for input and output. You have



    locale:
    [1] C


    but if you want to print non-ASCII characters such as ±, you'll need something such as UTF-8. One example of how to accomplish this (which seems to have solved your issue per the comments) is



    Sys.setlocale("LC_ALL","en_US.UTF-8")
    paste0("first_string", 2, "±", 3, "second_string", collapse = "")


    which should output



    [1] "first_string2±3second_string"


    For further information, I'd check out the following sources as a starting point:



    • R help page for getting or setting the locale

    • RStudio support on character encoding


    • readr's locale vignette





    share|improve this answer



























      2














      Locale settings control character sets for input and output. You have



      locale:
      [1] C


      but if you want to print non-ASCII characters such as ±, you'll need something such as UTF-8. One example of how to accomplish this (which seems to have solved your issue per the comments) is



      Sys.setlocale("LC_ALL","en_US.UTF-8")
      paste0("first_string", 2, "±", 3, "second_string", collapse = "")


      which should output



      [1] "first_string2±3second_string"


      For further information, I'd check out the following sources as a starting point:



      • R help page for getting or setting the locale

      • RStudio support on character encoding


      • readr's locale vignette





      share|improve this answer

























        2












        2








        2







        Locale settings control character sets for input and output. You have



        locale:
        [1] C


        but if you want to print non-ASCII characters such as ±, you'll need something such as UTF-8. One example of how to accomplish this (which seems to have solved your issue per the comments) is



        Sys.setlocale("LC_ALL","en_US.UTF-8")
        paste0("first_string", 2, "±", 3, "second_string", collapse = "")


        which should output



        [1] "first_string2±3second_string"


        For further information, I'd check out the following sources as a starting point:



        • R help page for getting or setting the locale

        • RStudio support on character encoding


        • readr's locale vignette





        share|improve this answer













        Locale settings control character sets for input and output. You have



        locale:
        [1] C


        but if you want to print non-ASCII characters such as ±, you'll need something such as UTF-8. One example of how to accomplish this (which seems to have solved your issue per the comments) is



        Sys.setlocale("LC_ALL","en_US.UTF-8")
        paste0("first_string", 2, "±", 3, "second_string", collapse = "")


        which should output



        [1] "first_string2±3second_string"


        For further information, I'd check out the following sources as a starting point:



        • R help page for getting or setting the locale

        • RStudio support on character encoding


        • readr's locale vignette






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 23:10









        duckmayrduckmayr

        7,30811326




        7,30811326



























            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%2f53289992%2fhow-to-print-the-sign-%25c2%25b1-in-a-string-in-r-to-place-this-character-in-a-table-l%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







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands