Reputation: 657
Problem: Same code, same data but different output.
I recently hired a someone and set him up on R. When we try to knit a .pdf file using the same .rmd file with the same data we get different results. In short, the code reads an Excel file and writes out a value from one of the cells. From my PC, the output is "100,000". From his PC, it appears as "1e+05". The question is how do I make the output "100,000" from both computers? As you look at the code you will see that I'm printing a vector using the code
av$PreTaxValue <- prettyNum(round(av$PreTaxValue, 0), big.mark = ",")
It's odd to me that one number in the vector is in scientific notation, and the other values have a comma.
I placed the markdown (.rmd) file, the Excel data, and the two (one from each computer) .PDF output files into a Github repo. When knitted the .rmd creates a .pdf. The Control.xlsx workbook has the data. debug1.pdf has the output the way I think it should be. The Taxable row, PreTaxvValue column has "100,000". In debug.pdf, this value appears as "1e05"
R.Version() from my PC produces:
$platform
[1] "x86_64-w64-mingw32"
$arch
[1] "x86_64"
$os
[1] "mingw32"
$system
[1] "x86_64, mingw32"
$status
[1] ""
$major
[1] "3"
$minor
[1] "5.1"
$year
[1] "2018"
$month
[1] "07"
$day
[1] "02"
$svn rev
[1] "74947"
$language
[1] "R"
$version.string
[1] "R version 3.5.1 (2018-07-02)"
$nickname
[1] "Feather Spray"
From my colleague's PC: R.Version() produces:
$platform
[1] "x86_64-w64-mingw32"
$arch
[1] "x86_64"
$os
[1] "mingw32"
$system
[1] "x86_64, mingw32"
$status
[1] ""
$major
[1] "3"
$minor
[1] "5.1"
$year
[1] "2018"
$month
[1] "07"
$day
[1] "02"
$svn rev
[1] "74947"
$language
[1] "R"
$version.string
[1] "R version 3.5.1 (2018-07-02)"
$nickname
[1] "Feather Spray"
Upvotes: 1
Views: 93
Reputation: 16920
As Alaleh A mentioned in a comment, you can essentially disable scientific notation by changing the global scipen
option:
options(scipen=100)
as discussed in this Stack Overflow question. However, if you don't want that as a global setting, you can change
prettyNum(round(av$PreTaxValue, 0), big.mark = ",")
to
prettyNum(format(round(av$PreTaxValue, 0), scientific = FALSE), big.mark = ",")
(and similarly for av$AfterTaxValue
). Consider the following:
x = 100000.00
prettyNum(round(x, 0), big.mark = ",")
#> [1] "1e+05"
prettyNum(format(round(x, 0), scientific = FALSE), big.mark = ",")
#> [1] "100,000"
Upvotes: 1