Documenter.jl: #autodocs for specific source files - julia

From Documenter.jl's documentation of #autodocs:
[...], a Pages vector may be included in #autodocs to filter
docstrings based on the source file in which they are defined:
```#autodocs
Modules = [Foo]
Pages = ["a.jl", "b.jl"]
```
However, it also says
Note that page matching is done using the end of the provided strings
and so a.jl will be matched by any source file that ends in a.jl, i.e.
src/a.jl or src/foo/a.jl.
How can I restrict the #autodocs block to specific source files?
My package's source code is organized as
src/
foo/a.jl
foo/b.jl
ignore/a.jl
ignore/b.jl
other.jl
How to make the #autodocs block only consider files src/foo/a.jl and src/foo/b.jl but not src/ignore/a.jl and src/ignore/b.jl?
Unfortunately, Pages = ["foo/a.jl", "foo/b.jl"] didn't do it for me.
Thanks in advance.
x-ref: https://discourse.julialang.org/t/documenter-jl-autodocs-for-specific-source-files/8784
x-ref: https://github.com/JuliaDocs/Documenter.jl/issues/630

Turns out that this is a Windows issue due to absence of normalization of path separators (see linked github issue).
On Linux Pages = ["foo/a.jl", "foo/b.jl"] should work.
On Windows Pages = ["foo\\a.jl", "foo\\b.jl"] should work.
EDIT: joinpath.("foo", ["a.jl", "b.jl"]) should work on any OS.

Related

Attempting to access images using R

So I am following the guide here which indicates the way to access photos is as follows:
flags <- c(
system.file("img", "flag", "au.png", package = "ggpattern"),
system.file("img", "flag", "dk.png", package = "ggpattern")
)
My goal is to now use this code for my own uses, so I saved a few images in a folder. Here is my directory:
"C:/Users/Thom/Docs/Misc/Testy"
And within the Testy folder, there is a folder called image, holding 3 images. But the following doesn't seem to work and idk why...
images <- c(
system.file("image", "image1.png", package = "ggpattern"),
system.file("image", "image2.png", package = "ggpattern")
)
system.file is for use when a file included in a package. Basically, it will look for the file starting its search path to where your R packages are installed (because this can vary from user to user). system.file will return the resolved path to the file locally
If you already know the absolute path on your local computer (i.e. "C:/Users/Thom/Docs/Misc/Testy") you can use that as just the input to a read function, e.g. readBin("C:/Users/Thom/Docs/Misc/Testy")
If you want to get a little fancy or are like me and can't ever remember which direction of a slash to use on which OS, you can also do something like this which will add in the OS specific path separator:
readBin(file.path("C:", "Users", "Thom", "Docs", "Misc", "Testy"))

Unable to use here() to get to the correct project directory

I have this weird problem. I was able to get here() to work but it stopped working and I can't figure out how to fix it.
So basically the structure of my file is like:
C:/First/Second/Third/Analysis/Scripts
C:/First/Second/Third/Analysis/Data
I want to easily bounce between data and scripts in the code
If I type here("C:/First/")
and then follow up with here(), R says that I'm at
C:/First/Documents
I'm not able to type here("Second", "Third", "Analysis", "Data", "todayscode.R")
because it puts me in the folder:
C:/First/Documents/Second/Third/Analysis/Data/
Which obviously does not exist.
It's unclear why you say that C:/First/Documents/Second/Third/Analysis/Data/ "does not exist". You will need to create a subdirectory if it doesn't exist, but at the beginning of your problem presentation you implied that was an existing directory.
Sounds like you want something like this possibilities:
setwd("C:/First/Second/Third/Analysis/")
You should first clarify where your version of the here function is coming from by typing here at the console input line and noting which namespace it comes from. If you then wanted to refer to a directory with that starting point you could use this (using the example set up in the here package at the here help page):
library(here); library(readr)
readr::read_csv(
here("data", "penguins.csv"),
col_types = list(.default = readr::col_guess()),
n_max = 3
)

box_dir_create() function from boxr package is not creating a folder in Box

I've been having difficulty getting boxr to successfully create a file within my box directory. My code reads:
library(boxr)
box_auth()
my_file_dir <- box_setwd("76009318507")
box_dir_create(dir_name="TEST", parent_dir_id = my_file_dir)
after running which, I get the following output:
box.com remote folder reference
name :
dir id :
size :
modified at :
created at :
uploaded by :
owned by :
shared link : None
parent folder name :
parent folder id :
Checking my box directory, I find no folders have been created.
I've tried using additional arguments within box_dir_create, but according to the documentation only dir_name and parent_dir_name are accepted.
Any help is much appreciated. I understand this is a somewhat obscure R package, so I've included links to the documentation below:
https://cran.r-project.org/web/packages/boxr/boxr.pdf
https://github.com/r-box/boxr
I got an answer via the package's developer, and I figured I'd pay it forward for any fellow travelers in the future.
It turns out that box_setwd() sets a default directory but returns nothing. Using
box_dir_create(dir_name="TEST", parent_dir_id = "76009318507")
creates the folder successfully. It will not do so if a folder of the same name is already created.
After more digging, I was also told that box_dir_create() is quietly passing back a lot of useful information, including the newly created directory's ID. To access it you can save the function results as a variable, like so:
b <- box_dir_create("test_dir")
names(b) # lots of info
b$id # what you want
box_ul(b$id, "image_file.jpg") # is this file by file?
box_push(b$id, "image_directory/") # or a directory wide operation?
Thanks for your help, and I hope this helps someone else down the road. Cheers!

Naming of downloaded pdf-files does not work

When downloading many (48) pdf-files the nameing using str_match(myurl, "UniqueID=(.+)) fails. I see that the downloads goes fine but name does not work and when its done I have only one file named "NA".
I am downloading a number of pdfs from a UN organisation database. This is going fine as I see that all files being downloaded. However, all files naming goes wrong and in the end I have only one file called "NA".
library(downloader)
library(stringr)
for (myurl in pdfscollect) {
filename<-paste("collected/", str_match(myurl, "UniqueID=(.+)")[2], ".pdf", sep="")
download(myurl, filename)
Sys.sleep(2)
}
I would expect all pdfs being named uniquely, but no naming happens and only one file in the end with "NA".
pdfscollect is file with all links. Example:
pdfstest<-c("http://www.ilo.org/evalinfo/product/download.do;?type=document&id=8287", "http://www.ilo.org/evalinfo/product/download.do;?type=document&id=10523",….)
If I understand correctly (?) the problem is that
paste("collected/", str_match(myurl, "UniqueID=(.+)")[2]
is returning a vector of NA when you are expecting the document ids:
[1] "8287" "10523"
I suggest using instead something like the following (which does get the expected output):
str_extract(pdfstest, "(?<=id=)\\d+")
Here we use regular expressions to match any number of digits that follow immediately after the first id= of the urls in your vector.
Thanks for the suggestion, #sindri_baldur. Acutally the result turns out the same, except that the name of the pdf file changes. I cannot open the pdf-file it either, I realise now. I think some of the problem is that the pdf-link is an "..download.do..." link (ilo.org/evalinfo/product/download.do;?type=document&id=8287). I guess I should fine another way to collect these pdfs.

file.create syntax

Super big newbie to R. I'm a bit stuck on the file.create function. I've used it successfully to create a file in the set working directory and also when I've already created a separate file path and assigned that file path to a variable.
However, why can't I use file.create and simply list the desired file path and file name without the file.path function? Does the file.create function not possess the capacity to automatically create the file in the specified directory, but requires the file.path function to secure the path to the directory?
Any clarification would be greatly appreciated. I do apologize if this question is rather elementary but I'd like to get the fundamentals down.
Here's the code that worked:
BasicDir <- "/Users/slam1924/Desktop/LearnR Tutorials"
setwd(BasicDir)
file.create("myfile.doc")
fp1 <- file.path("/Users/slam1924/Desktop/Vocal Covers", "mytext.doc")
fp1
file.create(fp1)
Alternative:
file.create(file.path("/Users/slam1924/Desktop/Vocal Covers", "mytext.doc"))
Here's the code that failed:
file.create("/Users/slam1924/Desktop/Vocal Covers", "mytext.doc")
Start by reading the help for the function. help(file.create). The usage is file.create(..., showWarnings = TRUE)
Under Details you'll see
file.create creates files with the given names if they do not already
exist and truncates them if they do.
So when you try
file.create("/Users/slam1924/Desktop/Vocal Covers", "mytext.doc")
It's trying to create two files, one of which ("/Users/slam1924/Desktop/Vocal Covers") is likely already a directory.
If the file or directory already exists, you'll see an error like:
[1] FALSE
Warning message:
In file.create("data") :
cannot create file 'data', reason 'Permission denied'
You could fix this by sending the function one string. Change your code that failed to:
file.create("/Users/slam1924/Desktop/Vocal Covers/mytext.doc")

Resources