I can't seem to give a table made with gt() a caption with Quarto and hence I can't cross-reference it. Using kable() works fine though. Minimal example here:
---
format: html
---
```{r}
#| include: false
library(gt)
library(knitr)
```
```{r}
#| echo: false
#| label: tbl-mytable
#| tbl-cap: "Caption"
head(mtcars) %>% gt()
```
#tbl-mytable
```{r}
#| echo: false
#| label: tbl-mytable2
#| tbl-cap: "Caption"
head(mtcars) %>% kable()
```
#tbl-mytable2
From what I could tell, gt should be supported by Quarto, so what am I doing wrong?
Related
I just discovered that running (y <- 1:4) prints the result in the console, but ...
(y <- 1:4)
# [1] 1 2 3 4
library(dplyr) # for the pipe operator %>%
y <- 1:4 %>% funct_parenthesis() # DOES IT EXIST ?
# [1] 1 2 3 4
print works
library(dplyr) # for the pipe operator %>%
y <- 1:4 %>% print
# [1] 1 2 3 4
I've set up a custom locale to get ActiveSupport to use short suffixes when calling number_to_human. Instead of number_to_human(123456) => '123.4 Thousand', it gives me number_to_human(123456) => '123.4k'.
This all works fine. What doesn't work is that while the default locale would leave smaller numbers alone (i.e. number_to_human(56) => 56), my custom locale doesn't. I've left the suffixes for units, tens, and hundreds blank, but this results in number_to_human(52) => '5.2' (i.e. 5.2 tens) or number_to_human(123) => '1.23' (for 1.23 hundreds).
How do I tell ActiveSupport not to use units, tens, or hundreds at all - to just leave numbers under 1000 alone?
Here's the locale file, if it helps (config/locales/en-ABBREV.yml):
en-ABBREV:
datetime:
distance_in_words:
x_seconds: '%{count}s'
x_minutes: '%{count}m'
about_x_hours: '%{count}h'
x_hours: '%{count}h'
x_days: '%{count}d'
x_weeks: '%{count}w'
about_x_months: '%{count}mo'
x_months: '%{count}mo'
x_years: '%{count}y'
number:
human:
unit: ''
ten: ''
hundred: ''
thousand: 'k'
million: 'm'
billion: 'b'
trillion: 't'
quadrillion: 'qd'
And my calls to number_to_human in the view look like this:
number_to_human #posts.count, precision: 1, significant: false, locale: 'en-ABBREV',
units: 'number.human', format: '%n%u'
Looking at the docs of that method I think you can define the unit you want to use like the following. When a key (like tens) is not included in the units then that units will just not be used.
number_to_human(
#posts.count,
format: '%n%u',
precision: 1,
significant: false
units: {
thousand: 'k',
million: 'm',
billion: 'b',
trillion: 't',
quadrillion: 'qd'
}
)
i am trying to convert some digits to currency and human friendly format in ruby on rails.
i know it could be done like this number_to_currency(number_to_human(4000000)) but for some reason im trying to do it like this.
eg. something like this 4000000.to_s(:human).to_s(:currency) => "$4 Million"
it this possible somehow ?
You're looking for number_to_human.
number_to_currency(number_to_human(4000000))
Try to write this code in en.yml as the following:
number:
currency:
format:
delimiter: ! ','
format: ! '%u%n'
precision: 2
separator: .
significant: false
strip_insignificant_zeros: false
unit: $
format:
delimiter: ! ','
precision: 3
separator: .
significant: false
strip_insignificant_zeros: false
human:
decimal_units:
format: ! '%n %u'
units:
billion: Billion
million: Million
quadrillion: Quadrillion
thousand: Thousand
trillion: Trillion
unit: ''
format:
delimiter: ''
precision: 3
significant: true
strip_insignificant_zeros: true
and write the following code:
number_to_currency(number_to_human(4000000))
read about number_to_human from these: link_1, and link_2
This my first time asking a question so please go easy one me :-p
I am following the examples on http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials (Section 3.4.5 Rendering Collections) for rendering collections using partials. The code looks simple, but clearly I am missing something.
models/expert.rb contains the line:
attr_accessible :name
experts_controller.rb contains the following line in the index method:
#experts = Expert.all
views/experts/index.html.erb contains the following line:
<%= render :partial => "expert", :collection => #experts %>
views/experts/_expert.html.erb contains:
<%= expert.name %>
Upon viewing the index page in my browser I get the following error:
NoMethodError in Experts#index
undefined method `name' for nil:NilClass
I have been working on this for an hour and am completely stumped :-/ What little thing am I missing?
---Clarification---
Running '<%= debug #experts %>' within index.html.erb produces the following output:
- !ruby/object:Expert
attributes:
id: 1
name: Bob Smith
slug: bob-smith
created_at: '2012-03-11 18:37:11.791118'
updated_at: '2012-03-11 18:55:58.179629'
changed_attributes: {}
previously_changed: {}
attributes_cache: {}
marked_for_destruction: false
destroyed: false
readonly: false
new_record: false
- !ruby/object:Expert
attributes:
id: 2
name: Steve Kamp
slug: steve-kamp
created_at: !!null
updated_at: !!null
changed_attributes: {}
previously_changed: {}
attributes_cache: {}
marked_for_destruction: false
destroyed: false
readonly: false
new_record: false
The exception almost certainly means that there are no experts, so #experts is an empty array. Have you created any expert records yet?
Also, just so you'll know, to render a collection of objects the way you're doing there's a nice shortcut:
render #experts
I have got this haml/mustache template:
{{#data}}
ok
{{#items}}
{{#item}}
%b ID: {{id}}
{{/item}}
{{/items}}
{{/data}}
And I have got Illegal nesting: nesting within plain text is illegal Error.
I render it in Sinatra
Mustache.render(haml(:index), hash)
I'm not sure about rendering with Sinatra, but with this command:
cat example.yml foo.haml.mustache | mustache | haml -e
this data file example.yml
---
data:
- items:
- item:
- id: 1
- id: 2
- id: 3
---
and template (foo.haml.mustache ):
{{#data}}
#ok
{{#items}}
{{#item}}
%b ID: {{id}}
{{/item}}
{{/items}}
{{/data}}
I get following result:
<div id='ok'>
<b>ID: 1</b>
<b>ID: 2</b>
<b>ID: 3</b>
</div>
Pls pay attention to indentation level in *.mustache file. Hope this help you.