Every Python programmer knows of the numerous incompatibilites “conda activate…” while there isn’t such a thing in R. Well until now… or at least as I learned it today…
We’re thrilled to announce the release of renv 1.0.0. renv has been around since 2019 as the successor to packrat, but this is the first time (!!) we’re blogging about it.
It seems that also graphic design tasks are more and more shifted to the authors. A journal asked me to revise my R “figures with >6 px size fonts at 600 dpi” which does not make so much sense to me as it mixes apples and oranges (DPI and PPI) and does even give me any size estimate of the final image.
In summary PPI are number of pixels per inch. Pixel is the smallest unit that can be displayed on a screen, the picture xelement. So my screen has about 227 ppi which is super sharp while for historical reasons not the physical but a logical PPI of 96 is being assumed for screens. Continue reading DPI and PPI in scientific publications→
Most recently I had to add forgotten data to a SQL server database that was in use only until 2010. Script language was Cold Fusion at that time creating a visual interface to 96 well plates where proband IDs are assigned to plate positions by drop down fields.
R doesn’t have any good way for formatted data entry. Some shiny apps would be helpful but a bit overkill here. Data export into a javascript framework would be also a more professional solution while I just needed only a quick way to modify my database.
So I came up with some R code producing html code embedding javascript functions that can export the result as SQL code, so a 4 language mixup.
96 well plate assignment
dataentry <- function(plate_id,city) {
# get orig IDs from database first
# position identifier A01, A02...
pos = NULL
for (i in 1:8) {
pos = c(pos, paste0( rep( LETTERS[i], 12), str_pad( 1:12 ,2,pad="0" ) ) )
}
HTML <- paste('<html>
<script>
function download(filename, text) {
var element = document.createElement("a");
element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text));
element.setAttribute("download", filename);
element.style.display = "none";
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function saveValues() {
var frm = document.getElementById("f");
var params = "";
var sample_id = ',sample_id,';
for( var i=0; i<frm.length; i++ ) {
sample_id++;
var fieldId = frm.elements[i].id;
var fieldValue = frm.elements[i].value;
if (fieldValue) params += "INSERT INTO samples (plate_id,plate_position,patient_id) VALUES (',plate_id,'," + fieldId + "," + fieldValue + ")\\n";
}
download("',plate_id,'.SQL",params);
}
</script>
<body>
<form id="f">')
# dropdowns
sel ='<option value=""></option>'
for (i in 1:dim(patients)[1]) {
sel <- paste0(sel,'<option value=',patients[i,"patient_id"],'>',patients[i,"Orig_ID"],'</option>\n')
}
for (i in pos) {
if (substr(i,2,3) == "01") HTML <- paste0(HTML,'<BR>')
HTML <- paste(HTML,'<select id=',i,'>',sel,'</select>')
}
HTML <- paste(HTML,'</form>
<br><input name="save" type="button" value="SQL" onclick="saveValues(); return false"/>
</body></html>')
sink( paste('plate.html') )
cat(HTML)
sink()
}
dataentry(725,'city')
Data were available for 2 of 65 RCTs (3.1%) published before the ICMJE policy and for 2 of 65 RCTs (3.1%) published after the policy was issued (odds ratio, 1.00; 95% CI, 0.07-14.19; P > .99).
Among the 89 articles declaring that IPD would be stored in repositories, only 17 (19.1%) deposited data, mostly because of embargo and regulatory approval.
Of 3556 analyzed articles, 3416 contained DAS. The most frequent DAS category (42%) indicated that the datasets are available on reasonable request. Among 1792 manuscripts in which DAS indicated that authors are willing to share their data, 1670 (93%) authors either did not respond or declined to share their data with us. Among 254 (14%) of 1792 authors who responded to our query for data sharing, only 122 (6.8%) provided the requested data.
Both issues took me many years of my scientific life. It is recognized by politics in Germany but also the most recent action plan looks … ridiculous. Why not making data and software sharing mandatory at time of publication?
I found it extremely difficult to control a webbrowser running in a Docker container – looking up the DOM tree, injecting javascript etc is a lot of guess work.
So we need also a VNC server in the docker container as found at github.
After starting in the terminal
docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm selenium/standalone-chrome:4.0.0-beta-1-prerelease-20210207
we can watch live at vnc://127.0.0.1:5900 what’s going on.
Having several long and redundant chains in R ‘s magittr code, I have now figured out how to pipe into named and unnamed functions
f1 <- function(x) {
x %>% count() %>% print()
}
f2 <- function(x) {
x %>% tibble() %>% print()
}
So we have now two named functions with code blocks that can be inserted in an unnamed function whenever needed
iris %>%
# do any select, mutate ....
# before running both functions
(function(x) {
x %>% select(Species) %>% f1() %>% print()
x %>% f2() %>% print()
})
We can make a variable global from inside a function using <<- assignment but I have not found a way to continue the dplyr chain with any returned variable. So we are trapped inside the function
iris %>%
(function(x) {
result <<- x %>% head(1)
})
Although having some experience with leaflet before, it took me 5 hours to find out how to
(1) change the background color and
(2) re-center my map after the popup was panning the map basically out view. Here is my solution
A recent paper identifies 10 rules for better pictures. As I have also given several lectures on that topic, I was excited what the authors think…
1. Know your audience. This is trivial as you never know your audience.
2. Identify your message. True and not true at the same time. True as it makes your findings more evident – not true if you are allowing a reader to find his own message.
3. Adapt the figure to the support medium. Trivial. May be very time consuming.
4. Captions are not optional. Absolutely true, I also suppport good captions – mini stories for those who can’t read the whole text.
5. Do not trust the defaults. Trivial. No one does.
6. Use color efficiently. Not really, avoid colors for those of us who are colorblind and to avoid expensive page charges.
7. Do not mislead the reader. Why should I?
8. Avoid Chartjunk. Absolutely. Most frequent problem.
9. Message trumps beauty. Sure, form follows function.
10. Get the right tool. Maybe correct while the further recommendations look like a poor man’s effort to make his first graphic at zero cost: Gimp, Imagemagick, R…