-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdocs.qmd
More file actions
348 lines (314 loc) · 10.7 KB
/
Copy pathdocs.qmd
File metadata and controls
348 lines (314 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
---
title: "Data documentation"
---
Click on each dataset's name to see its description, license, citation, and link to its original source. Code used to create these data can be found [here](https://github.com/ben-domingue/irw/tree/main/data).
**Every dataset here has been modified.** IRW does not redistribute source files: each one is reshaped into the [IRW data standard](standard.qmd) — long format, one row per person-item response, with columns renamed and non-response material dropped. The processing script for a given dataset is the record of exactly what was changed, and is linked above. The license shown beside each description is the **source's** license, which continues to govern reuse of that dataset: where it carries a non-commercial restriction, that restriction travels with IRW's copy.
```{=html}
<div class="panel-tabset-container">
<button onclick="toggleTabset()">To cite using IRW's R package</button>
<div class="panel-tabset" style="display: none;">
<div class="r-command">
<p>> <code>irw_save_bibtex("gilbert_meta_48")</code></p>
</div>
<div class="bibtex-entry">
<pre>
@misc{gilbert_meta_48,
doi = {10.7910/DVN/3SF36J},
url = {https://dataverse.harvard.edu/citation?persistentId=doi:10.7910/DVN/3SF36J},
author = {Cárdenas, Sergio and Evans, David K.},
keywords = {Social Sciences},
title = {Replication Data for: Parent Training and Child Development at Low Cost? Evidence from a Randomized Field Experiment in Mexico},
publisher = {Harvard Dataverse},
year = {2023}
}
</pre>
</div>
</div>
</div>
<style>
/* Style for the toggle button */
.panel-tabset-container button {
margin-bottom: 10px;
padding: 5px 10px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.panel-tabset-container button:hover {
background-color: #0056b3;
}
/* Style for the panel content */
.panel-tabset {
display: none; /* Hide by default */
border: 1px solid #ddd;
padding: 10px;
border-radius: 4px;
background: #f9f9f9;
font-family: 'Courier New', Courier, monospace;
}
/* Style for the R command line */
.r-command {
margin-bottom: 15px;
color: #333;
font-size: 14px;
}
.r-command p {
margin: 0;
padding: 5px;
background-color: #f3f3f3;
border-left: 3px solid #007BFF;
font-family: monospace;
}
/* Style for the BibTeX block */
.bibtex-entry pre {
background-color: #f3f3f3;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
font-family: monospace;
font-size: 14px;
overflow-x: auto;
}
</style>
<script>
function toggleTabset() {
const tabset = document.querySelector('.panel-tabset');
tabset.style.display = (tabset.style.display === 'none' || tabset.style.display === '') ? 'block' : 'none';
}
</script>
```
```{r}
library(dplyr)
library(purrr)
library(readr)
library(stringr)
library(glue)
library(redivis)
biblio <- redivis$user("datapages")$dataset("irw_meta:bdxt:latest")$table("biblio")$to_tibble()
# Load datasets
data_index <- biblio |>
rename(dataset = `table`, url = URL__for_data_, license = `Derived_License`,
description = Description, reference = Reference_x, doi = DOI__for_paper_) |>
mutate(dataset = str_remove(dataset, ".R.ata$")) |>
arrange(dataset)
```
```{=html}
<input type="text" id="searchBar" placeholder="Search datasets..." style="width: 100%; padding: 10px; margin-bottom: 20px; font-size: 16px;">
<p id="search-placeholder" style="color: #888;">Start typing to search across all datasets by name, description, or reference.</p>
<script>
function searchDatasets() {
var input = document.getElementById('searchBar');
var filter = input.value.toLowerCase().trim();
var items = document.getElementsByClassName('dataset-item');
var table = document.getElementById('dataset-table-wrapper');
var placeholder = document.getElementById('search-placeholder');
if (filter === '') {
table.style.display = 'none';
placeholder.style.display = '';
return;
}
table.style.display = '';
placeholder.style.display = 'none';
for (var i = 0; i < items.length; i++) {
var text = items[i].textContent || items[i].innerText;
items[i].style.display = text.toLowerCase().indexOf(filter) > -1 ? '' : 'none';
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function getCitation(bibtex, buttonId, targetId) {
const button = document.getElementById(buttonId);
button.disabled = true;
button.textContent = 'Loading...';
try {
await sleep(100); // Small delay for UI feedback
const target = document.getElementById(targetId);
const container = document.createElement('div');
container.className = 'citation-container';
const citationText = document.createElement('pre');
citationText.className = 'citation-pre';
citationText.textContent = bibtex;
const copyButton = document.createElement('button');
copyButton.className = 'copy-button';
copyButton.innerHTML = '📋 Copy';
copyButton.onclick = () => {
navigator.clipboard
.writeText(bibtex)
.then(() => {
copyButton.innerHTML = '✓ Copied!';
setTimeout(() => (copyButton.innerHTML = '📋 Copy'), 2000);
})
.catch(() => (copyButton.innerHTML = '❌ Error'));
};
target.innerHTML = '';
container.appendChild(citationText);
container.appendChild(copyButton);
target.appendChild(container);
target.style.display = 'block';
} catch (error) {
console.error('Error displaying citation:', error);
const target = document.getElementById(targetId);
target.textContent = 'Error displaying citation. Please try again.';
target.style.display = 'block';
} finally {
button.disabled = false;
button.textContent = 'Get BibTex';
}
}
document.getElementById('searchBar').addEventListener('input', searchDatasets);
</script>
<style>
.citation-container {
position: relative;
margin-top: 10px;
padding: 10px;
background-color: #f5f5f5;
border-radius: 4px;
min-height: 50px;
}
.citation-pre {
font-family: monospace;
white-space: pre-wrap;
word-wrap: break-word;
margin: 0;
padding: 20px 10px 10px 10px;
max-width: 100%;
overflow-x: auto;
}
.copy-button {
position: absolute;
top: 5px;
right: 5px;
background-color: #ffffff;
border: 1px solid #dddddd;
border-radius: 4px;
padding: 4px 8px;
cursor: pointer;
font-size: 12px;
z-index: 1;
}
.copy-button:hover {
background-color: #f0f0f0;
}
.citation-button {
background-color: #007bff;
color: white;
border: none;
padding: 5px 10px;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
.citation-button:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
.dataset-table {
width: 100%;
table-layout: fixed;
border-collapse: collapse;
font-size: 15px;
}
.dataset-table th, .dataset-table td {
padding: 10px 12px;
border-bottom: 1px solid #e2e2e2;
text-align: left;
vertical-align: top;
overflow-wrap: break-word;
}
.dataset-table th {
border-bottom: 2px solid #ccc;
font-weight: 600;
}
.dataset-table tr:hover {
background-color: #f7f7f7;
}
.dataset-table th:nth-child(1), .dataset-table td:nth-child(1) { width: 16%; }
.dataset-table th:nth-child(2), .dataset-table td:nth-child(2) { width: 58%; }
.dataset-table th:nth-child(3), .dataset-table td:nth-child(3) { width: 8%; }
.dataset-table th:nth-child(4), .dataset-table td:nth-child(4) { width: 18%; }
</style>
```
```{r}
#| results: asis
# A dataset's license is recorded as a name; the license itself lives elsewhere.
# Reusers need the terms, not the label -- and where a source is offered under a
# non-commercial or share-alike license, its own conditions ask that anyone
# redistributing it link to that license rather than merely name it. So the
# name is rendered as a link wherever there is a canonical text to point at.
# Values with no such text -- "Custom", "Permission via Email" -- render as
# plain text, which is the honest rendering: there is nothing to link to. So
# does "CC BY-NC-ND", deliberately: it is recorded without a version, and
# guessing 4.0 would put a wrong link on the one license whose terms most need
# reading.
license_urls <- c(
"CC0 1.0" = "https://creativecommons.org/publicdomain/zero/1.0/",
"CC BY 4.0" = "https://creativecommons.org/licenses/by/4.0/",
"CC BY-SA 4.0" = "https://creativecommons.org/licenses/by-sa/4.0/",
"CC BY-NC 4.0" = "https://creativecommons.org/licenses/by-nc/4.0/",
"CC BY-NC 3.0" = "https://creativecommons.org/licenses/by-nc/3.0/",
"CC BY-NC-SA 4.0" = "https://creativecommons.org/licenses/by-nc-sa/4.0/",
"CC BY-NC-SA 3.0" = "https://creativecommons.org/licenses/by-nc-sa/3.0/",
"ODbL 1.0" = "https://opendatacommons.org/licenses/odbl/1-0/",
"ODC-By" = "https://opendatacommons.org/licenses/by/1-0/",
"MIT" = "https://opensource.org/license/mit",
"GPL-2.0" = "https://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
"GPL-3.0" = "https://www.gnu.org/licenses/gpl-3.0.en.html",
"LGPL-3.0" = "https://www.gnu.org/licenses/lgpl-3.0.en.html"
)
# A few rows carry two comma-separated licenses, so link each part separately.
license_html <- function(x) {
if (is.null(x) || length(x) == 0 || is.na(x) || !nzchar(trimws(x))) return("")
parts <- trimws(strsplit(x, ",")[[1]])
parts <- parts[nzchar(parts)]
linked <- vapply(parts, function(part) {
url <- unname(license_urls[part])
if (is.na(url)) part
else glue('<a href="{url}" target="_blank" rel="license noopener">{part}</a>')
}, character(1))
glue("({paste(linked, collapse = ', ')})")
}
row <- function(ds) {
lic <- license_html(ds$license)
bibtex <- ds$BibTex # Use BibTex column directly
escaped_bibtex <- if (!is.na(bibtex) && bibtex != "") gsub("'", "\\\\'", bibtex) else ""
citation_button <- if (escaped_bibtex != "") {
button_id <- paste0("cite-button-", make.names(ds$dataset))
target_id <- paste0("cite-text-", make.names(ds$dataset))
glue(
'<button id="{button_id}" class="citation-button" onclick="getCitation(`{escaped_bibtex}`, \'{button_id}\', \'{target_id}\')">
Get BibTex
</button>
<div id="{target_id}" class="citation-text"></div>'
)
} else ""
glue(
'
<tr class="dataset-item">
<td><strong>{ds$dataset}</strong></td>
<td>{ds$description} {lic} <i>{ds$reference}</i></td>
<td><a href="{ds$url}" target="_blank">link</a></td>
<td>{citation_button}</td>
</tr>
'
)
}
rows <- transpose(data_index) |> map(row) |> paste(collapse = "\n")
cat(glue(
'
<div id="dataset-table-wrapper" style="display: none;">
<table class="dataset-table">
<thead>
<tr><th>Dataset</th><th>Description</th><th>Source</th><th>Citation</th></tr>
</thead>
<tbody>
{rows}
</tbody>
</table>
</div>
'
))
```