我试图隐藏格式正确的knitr :: kable()表格。没有隐藏它们看起来很好......但如果我显示已隐藏的表格,它们将显示为普通文本....这是我的代码到目前为止:
---
title: "Test-Tabellen"
output:
html_document:
code_folding: hide
---
<div id="BE_Genus_C.txt" style="display:none">
```{r cache=FALSE, collapse=TRUE, results='asis'}
test<-read.csv2("BE_Genus_C.txt", header=FALSE, sep="\t")
knitr::kable(test)
```
</div>
<button title="Click to show answer" type="button" onclick="if(document.getElementById('BE_Genus_C.txt') .style.display=='none') {document.getElementById('BE_Genus_C.txt') .style.display=''}else{document.getElementById('BE_Genus_C.txt') .style.display='none'}">Show/hide</button>
你知道我怎么能用另一种方式隐藏用knitr :: kable()生成的表吗?或者至少正确显示它们?
我为什么需要它的问题如下:我有大约100个小桌子,我不想直接看到......但我希望能够在需要时看看它们。 ..我也想把这些表格(附上一些解释)发给我的主管。
答案 0 :(得分:0)
这是因为pandoc tables should end with a blank line,所以在R代码块和关闭 (?m)
( # (1 start), Key
(?:
^
(?! \s )
[^:\n]*
\n?
)+
) # (1 end)
:
( # (2 start), Value
\h+ .*?
(?: \n | \z )
(?:
^ \h+ .*?
(?: \n | \z )
)*
)? # (2 end)
标记之间添加一个额外的行:
use strict;
use warnings;
$/ = undef;
my $smartdata = <DATA>;
my @key = ();
my @val = ();
while ( $smartdata =~ /(?m)((?:^(?!\s)[^:\n]*\n?)+):(\h+.*?(?:\n|\z)(?:^\h+.*?(?:\n|\z))*)?/g )
{
push @key, $1;
if (defined $2 ) {
push @val, $2;
}
else {
push @val, '';
}
}
for ( 0 .. ($#key-1) )
{
print "key $_ = $key[$_]\n";
print "value = $val[$_]\n-------------------\n";
}
__DATA__
Offline data collection status: (0x00) Offline data collection activity
was never started.
Auto Offline Data Collection: Disabled.
Self-test execution status: ( 0) The previous self-test routine completed
without error or no self-test has ever
been run.
Total time to complete Offline
data collection: ( 139) seconds.
Offline data collection
capabilities: (0x73) SMART execute Offline immediate.
Auto Offline data collection on/off support.
Suspend Offline collection upon new
command.
No Offline surface scan supported.
Self-test supported.
Conveyance Self-test supported.
Selective Self-test supported.
SMART capabilities: (0x0003) Saves SMART data before entering
power-saving mode.
Supports SMART auto save timer.
Error logging capability: (0x01) Error logging supported.
General Purpose Logging supported.
Short self-test routine
recommended polling time: ( 2) minutes.
Extended self-test routine
recommended polling time: ( 100) minutes.
Conveyance self-test routine
recommended polling time: ( 3) minutes.
SCT capabilities: (0x1081) SCT Status supported.
下次不要忘记使用可重现的示例(例如key 0 = Offline data collection status
value = (0x00) Offline data collection activity
was never started.
Auto Offline Data Collection: Disabled.
-------------------
key 1 = Self-test execution status
value = ( 0) The previous self-test routine completed
without error or no self-test has ever
been run.
-------------------
key 2 = Total time to complete Offline
data collection
value = ( 139) seconds.
-------------------
key 3 = Offline data collection
capabilities
value = (0x73) SMART execute Offline immediate.
Auto Offline data collection on/off support.
Suspend Offline collection upon new
command.
No Offline surface scan supported.
Self-test supported.
Conveyance Self-test supported.
Selective Self-test supported.
-------------------
key 4 = SMART capabilities
value = (0x0003) Saves SMART data before entering
power-saving mode.
Supports SMART auto save timer.
-------------------
key 5 = Error logging capability
value = (0x01) Error logging supported.
General Purpose Logging supported.
-------------------
key 6 = Short self-test routine
recommended polling time
value = ( 2) minutes.
-------------------
key 7 = Extended self-test routine
recommended polling time
value = ( 100) minutes.
-------------------
key 8 = Conveyance self-test routine
recommended polling time
value = ( 3) minutes.
-------------------
vs div
):)