{"id":6676,"date":"2022-08-06T20:33:42","date_gmt":"2022-08-06T20:33:42","guid":{"rendered":"https:\/\/www.garysieling.com\/blog\/?p=6676"},"modified":"2022-08-07T18:21:17","modified_gmt":"2022-08-07T18:21:17","slug":"r-convert-from-gib-mib-kib-to-bytes","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/r-convert-from-gib-mib-kib-to-bytes\/","title":{"rendered":"R: Convert from GiB, MiB, KiB to bytes"},"content":{"rendered":"\n<p>This function does the conversion, if there is no space between the number and the units:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>convert_to_bytes &lt;- function(value) {\n    digits &lt;- gsub(\"&#91;^0-9.]\", \"\", value)\n    units &lt;- gsub(\"&#91;0-9.]\", \"\", value)\n    multiplier &lt;- switch (units,\n                          'GiB' = 1024^3,\n                          'MiB' = 1024^2,\n                          'KiB'= 1024,\n                          'B' = 1)\n    \n    as.double(digits) * multiplier\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This function does the conversion, if there is no space between the number and the units:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6],"tags":[450],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6676"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=6676"}],"version-history":[{"count":1,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6676\/revisions"}],"predecessor-version":[{"id":6677,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6676\/revisions\/6677"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=6676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=6676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=6676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}